diff --git a/Sample.java b/Sample.java deleted file mode 100644 index 1739a9cbc..000000000 --- a/Sample.java +++ /dev/null @@ -1,7 +0,0 @@ -// Time Complexity : -// Space Complexity : -// Did this code successfully run on Leetcode : -// Any problem you faced while coding this : - - -// Your code here along with comments explaining your approach diff --git a/min stack problem b/min stack problem new file mode 100644 index 000000000..caecbad64 --- /dev/null +++ b/min stack problem @@ -0,0 +1,31 @@ +class MinStack { + Stackst; + Stack minst; + int min; + public MinStack() { + this.st=new Stack<>(); + this.minst=new Stack<>(); + this.min=Integer.MAX_VALUE; + this.minst.push(min); + } + + public void push(int val) { + min=Math.min(min,val); + 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; + } +}