Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed Design - 1 #2169

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
133 changes: 128 additions & 5 deletions Sample.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,130 @@
// 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)
// Did this code successfully run on Leetcode : YES
// Any problem you faced while coding this : NO


// Your code here along with comments explaining your approach

class MyHashSet {
int pkh;
int skh;
boolean[][] storage;

public MyHashSet() {
this.pkh = 1000;
this.skh = 1000;
this.storage = new boolean[pkh][];

}

public void add(int key) {

int pk = getphash(key);
if(storage[pk] == null){
if(pk == 0){
storage[pk] = new boolean[skh+1]
}
else{
storage[pk] = new boolean[skh];
}}
int sk = getshash(key);
storage[pk][sk]= true;


}

private int getphash(int key){
return key % pkh;
}

private int getshash(int key){
return key / skh;
}

public void remove(int key) {

int pk = getphash(key);
if(storage[pk] == null){
return;
}
int sk = getshash(key);
storage[pk][sk]= false;



}

public boolean contains(int key) {
int pk = getphash(key);
if(storage[pk] == null){
return false;
}
int sk = getshash(key);
return storage[pk][sk];

}
}

// Time Complexity : O(1)
// Space Complexity : O(1)
// Did this code successfully run on Leetcode : YES
// Any problem you faced while coding this : NO


/**
* 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);
*/

class MinStack {
Stack<Integer> st;
Stack<Integer> minSt;
int min;

public MinStack() {
this.st = new Stack<>();
this.minSt = new Stack<>();
this.min = Integer.MAX_VALUE;
minSt.push(min);
}

public void push(int val) {

min = Math.min(val,min);
st.push(val);
minSt.push(min);

}

public void pop() {

st.pop();
minSt.pop();
min = minSt.peek();


}

public int top() {
return st.peek();

}

public int getMin() {

return min;

}
}

/**
* 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();
*/