File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77| :----:| :-------------------------------------------------------------------:| :----------------------------------:| :----:| :--------------------------------------------------------------------------------:| :---------------------------------------:|
88| 1 | [ TwoSum] ( https://leetcode.com/problems/two-sum ) | [ cpp] ( source/TwoSum.cpp ) | 2 | [ PalindromeNumber] ( https://leetcode.com/problems/palindrome-number ) | [ cpp] ( source/PalindromeNumber.cpp ) |
99| 3 | [ ValidParentheses] ( https://leetcode.com/problems/valid-parentheses ) | [ cpp] ( source/ValidParentheses.cpp ) | 4 | [ MiddleOfTheLinkedList] ( https://leetcode.com/problems/middle-of-the-linked-list ) | [ cpp] ( source/MiddleOfTheLinkedList.cpp ) |
10- | 5 | [ PlusOne] ( https://leetcode.com/problems/plus-one ) | [ cpp] ( source/PlusOne.cpp ) | | | |
10+ | 5 | [ PlusOne] ( https://leetcode.com/problems/plus-one ) | [ cpp] ( source/PlusOne.cpp ) | 6 | [ MinStack ] ( https://leetcode.com/problems/min-stack ) | [ cpp ] ( source/MiddleOfTheLinkedList.cpp ) |
1111
1212</details >
Original file line number Diff line number Diff line change 1+ // PalindromeNumber
2+ // 2022.08.10
3+ // Medium
4+ class MinStack
5+ {
6+ public:
7+ stack<int > st;
8+ stack<int > minSt;
9+
10+ void push (int val)
11+ {
12+ st.push (val);
13+ if (minSt.size () == 0 )
14+ {
15+ minSt.push (val);
16+ }
17+ else if (val <= minSt.top ())
18+ {
19+ minSt.push (val);
20+ }
21+ }
22+
23+ void pop ()
24+ {
25+ int top = st.top ();
26+ if (top == minSt.top ())
27+ {
28+ minSt.pop ();
29+ }
30+ st.pop ();
31+ }
32+
33+ int top ()
34+ {
35+ return st.top ();
36+ }
37+
38+ int getMin ()
39+ {
40+ return minSt.top ();
41+ }
42+ };
You can’t perform that action at this time.
0 commit comments