Skip to content
Open

done #2617

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
22 changes: 22 additions & 0 deletions HashSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class MyHashSet {
Set <Integer> s;
public MyHashSet() {
s=new HashSet<>();
}

public void add(int key) {
s.add(key);
return ;
}

public void remove(int key) {
s.remove(key);
return ;
}

public boolean contains(int key) {
if(s.contains(key)) return true;
return false;
}
}

37 changes: 37 additions & 0 deletions MinStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*used two stack approach , one just noemal and one to store the min val */

class MinStack {
Stack <Integer> st;
Stack<Integer> mst;
public MinStack() {
st= new Stack<>();
mst= new Stack<>();
}

public void push(int val) {
st.push(val);
if(mst.isEmpty())
{
mst.push(val);
}

else
{
mst.push(Math.min(val, mst.peek()));
}
}

public void pop() {
st.pop();
mst.pop();
}

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

public int getMin() {
return mst.peek();
}
}