code >>
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
|
class MinStack {
public:
/** initialize your data structure here. */
vector<int> real_vector;
vector<int> save_min_vector;
MinStack() {
}
void push(int val) {
real_vector.push_back(val);
if (save_min_vector.empty() || save_min_vector.back() >= val)
save_min_vector.push_back(val);
}
void pop() {
if (real_vector.back() == save_min_vector.back())
{
save_min_vector.pop_back();
}
real_vector.pop_back();
}
int top() {
return real_vector.back();
}
int getMin() {
return save_min_vector.back();
}
};
|
'C' 카테고리의 다른 글
c++ leet code 227, Basic CalculatorII code (0) | 2021.07.12 |
---|---|
c++ leetcode 394 decode_string 풀이 (0) | 2021.07.12 |
c++ leetcode 1249 Minimum Remove to make valid parenthesis 문제풀이 (0) | 2021.07.08 |
c++ leet code 20. Valid Parentheses stack solution (0) | 2021.07.07 |
c++ leetcode O(N) solution Longest Substring Without repetition (0) | 2021.07.07 |