From ab25aa9cb41669095ff710c06dd4bb1d4c7572a4 Mon Sep 17 00:00:00 2001 From: Praniksha123 Date: Thu, 4 Jun 2026 06:26:51 +0530 Subject: [PATCH] Update and rename Sample.java to min stack problem --- Sample.java | 7 ------- min stack problem | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) delete mode 100644 Sample.java create mode 100644 min stack problem 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; + } +}