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 dc31034 commit cd1bb24Copy full SHA for cd1bb24
cpp/155-Min-Stack.cpp
@@ -0,0 +1,35 @@
1
+using namespace std;
2
+class MinStack {
3
+public:
4
+ stack<pair<int, int>> stk;
5
+ int m;
6
+
7
+ MinStack() {
8
+ m = INT_MAX;
9
+ }
10
11
+ void push(int val) {
12
+ stk.push({val, min(val, stk.empty()?INT_MAX:stk.top().second)});
13
14
15
+ void pop() {
16
+ if(!stk.empty()) stk.pop();
17
18
19
+ int top() {
20
+ return stk.top().first;
21
22
23
+ int getMin() {
24
+ return stk.top().second;
25
26
+};
27
28
+/**
29
+ * Your MinStack object will be instantiated and called as such:
30
+ * MinStack* obj = new MinStack();
31
+ * obj->push(val);
32
+ * obj->pop();
33
+ * int param_3 = obj->top();
34
+ * int param_4 = obj->getMin();
35
+ */
0 commit comments