diff --git a/HashSet.java b/HashSet.java new file mode 100644 index 00000000..d55d6b8c --- /dev/null +++ b/HashSet.java @@ -0,0 +1,22 @@ +class MyHashSet { +Set 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; + } +} + diff --git a/MinStack.java b/MinStack.java new file mode 100644 index 00000000..2eaeee6f --- /dev/null +++ b/MinStack.java @@ -0,0 +1,37 @@ +/*used two stack approach , one just noemal and one to store the min val */ + +class MinStack { +Stack st; +Stack 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(); + } +} +