- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminstack.cpp
More file actions
Latest commit
41 lines (36 loc) · 728 Bytes
/
Copy pathminstack.cpp
File metadata and controls
41 lines (36 loc) · 728 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
38
39
40
41
classMinStack {
public:
stack <int> box;
int min1 = INT32_MAX;
voidpush(int x) {
if(x<=min1)
{
box.push(min1);
min1 = x;
}
box.push(x);
}
voidpop() {
int up = box.top();
box.pop();
if(up==min1)
{
min1 = box.top();
box.pop();
}
}
inttop() {
return box.top();
}
intgetMin() {
return min1;
}
};
/**
* Your MinStack object will be instantiated and called as such:
* MinStack* obj = new MinStack();
* obj->push(x);
* obj->pop();
* int param_3 = obj->top();
* int param_4 = obj->getMin();
*/