-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path155.cpp
More file actions
37 lines (32 loc) · 816 Bytes
/
Copy path155.cpp
File metadata and controls
37 lines (32 loc) · 816 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
35
36
37
/*******************************************************************************
> File Name: 155.cpp
> Author: sillyplus
> Mail: oi_boy@sina.cn
> Created Time: Sun Mar 6 11:02:19 2016
*******************************************************************************/
class MinStack {
private:
stack<int> allStack;
stack<int> minStack;
public:
void push(int x) {
if (minStack.empty()) {
minStack.push(x);
} else if (x <= minStack.top()) {
minStack.push(x);
}
allStack.push(x);
}
void pop() {
if (allStack.top() == minStack.top()) {
minStack.pop();
}
allStack.pop();
}
int top() {
return allStack.top();
}
int getMin() {
return minStack.top();
}
};