-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.cpp
More file actions
34 lines (28 loc) · 702 Bytes
/
Copy path2.cpp
File metadata and controls
34 lines (28 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*************************************************************************
> File Name: 2.cpp
> Author: Louis1992
> Mail: zhenchaogan@gmail.com
> Blog: http://gzc.github.io
> Created Time: Mon Nov 9 12:34:25 2015
************************************************************************/
class MinStack {
stack<int> s1;
stack<int> s2;
public:
void push(int x) {
s1.push(x);
if(s2.empty() || s2.top() >= x) s2.push(x);
}
void pop() {
int tmp = s1.top();
s1.pop();
if(tmp == s2.top())
s2.pop();
}
int top() {
return s1.top();
}
int getMin() {
return s2.top();
}
};