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 ab52800 commit ba447f4Copy full SHA for ba447f4
155_Min_Stack.cc
@@ -0,0 +1,44 @@
1
+class MinStack {
2
+public:
3
+ /** initialize your data structure here. */
4
+ MinStack() {
5
+
6
+ }
7
8
+ void push(int x) {
9
+ s.push(x);
10
+ if(s_min.empty()||x<=s_min.top()){
11
+ s_min.push(x);
12
13
14
15
+ void pop() {
16
+ if(s.top()==s_min.top())
17
+ {
18
+ s_min.pop();
19
20
+ s.pop();
21
22
23
24
+ int top() {
25
+ return s.top();
26
27
28
+ int getMin() {
29
+ return s_min.top();
30
31
32
+private:
33
+ stack<int> s;
34
+ stack<int> s_min;
35
+};
36
37
+/**
38
+ * Your MinStack object will be instantiated and called as such:
39
+ * MinStack obj = new MinStack();
40
+ * obj.push(x);
41
+ * obj.pop();
42
+ * int param_3 = obj.top();
43
+ * int param_4 = obj.getMin();
44
+ */
0 commit comments