Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/Design-1.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions Problem3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Time Complexity: O(1)
// Space Complexity: O(N)

class MinStack {
private ArrayList<int[]> st;

public MinStack() {
st = new ArrayList<>();
}

public void push(int val) {
int[] top = st.isEmpty() ? new int[]{val, val} : st.get(st.size() - 1);
int min_value = top[1];
if (min_value > val) {
min_value = val;
}
st.add(new int[]{val, min_value});
}

public void pop() {
st.remove(st.size()-1);
}

public int top() {
return st.isEmpty() ? -1 : st.get(st.size() - 1)[0];
}

public int getMin() {
return st.isEmpty() ? -1 : st.get(st.size() - 1)[1];
}
}

/**
* Your MinStack object will be instantiated and called as such:
* MinStack obj = new MinStack();
* obj.push(val);
* obj.pop();
* int param_3 = obj.top();
* int param_4 = obj.getMin();
*/
35 changes: 31 additions & 4 deletions Sample.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
// Time Complexity :
// Space Complexity :
// Did this code successfully run on Leetcode :
// Any problem you faced while coding this :
// Time Complexity : O(1)
// Space Complexity : O(1) -> O(1000001)
// Did this code successfully run on Leetcode : Yes
// Any problem you faced while coding this : Initialized the boolean set with only 100 as the limit


// Your code here along with comments explaining your approach
class MyHashSet {
boolean[] set;

public MyHashSet() {
set = new boolean[1000001];
}

public void add(int key) {
set[key] = true;
}

public void remove(int key) {
set[key] = false;
}

public boolean contains(int key) {
return set[key];
}
}

/**
* Your MyHashSet object will be instantiated and called as such:
* MyHashSet obj = new MyHashSet();
* obj.add(key);
* obj.remove(key);
* boolean param_3 = obj.contains(key);
*/