We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2412608 commit cc488f2Copy full SHA for cc488f2
155. Min Stack
@@ -0,0 +1,34 @@
1
+class MinStack {
2
+public:
3
+ vector<pair<int,int>> st; //we have make a vector
4
+ MinStack() {
5
+
6
+ }
7
8
+ void push(int val) {
9
+ if(st.empty()){
10
+ pair<int,int>p;// = make_pair(val,val);
11
+ p.first = val;
12
+ p.second = val;
13
+ st.push_back(p);
14
15
+ else{
16
+ pair<int,int>p;
17
18
+ p.second = min(val, st.back().second);
19
20
21
22
23
+ void pop() {
24
+ st.pop_back();
25
26
27
+ int top() {
28
+ return st.back().first;
29
30
31
+ int getMin() {
32
+ return st.back().second;
33
34
+};
0 commit comments