We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a8e3209 commit 3cb46cfCopy full SHA for 3cb46cf
155-min-stack/155-min-stack.cpp
@@ -0,0 +1,40 @@
1
+class MinStack {
2
+public:
3
+ stack<int> s;
4
+ stack<int> ss;
5
+ MinStack() {
6
+
7
+ }
8
9
+ void push(int val) {
10
+ s.push(val);
11
+ if(ss.empty() || ss.top() >= val) {
12
+ ss.push(val);
13
14
15
16
+ void pop() {
17
+ int pop_value = s.top();
18
+ s.pop();
19
+ if(ss.top() == pop_value){
20
+ ss.pop();
21
22
23
24
+ int top() {
25
+ return s.top();
26
27
28
+ int getMin() {
29
+ return ss.top();
30
31
+};
32
33
+/**
34
+ * Your MinStack object will be instantiated and called as such:
35
+ * MinStack* obj = new MinStack();
36
+ * obj->push(val);
37
+ * obj->pop();
38
+ * int param_3 = obj->top();
39
+ * int param_4 = obj->getMin();
40
+ */
0 commit comments