We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 56b6641 + 48f823d commit 157c2d5Copy full SHA for 157c2d5
Leetcode - Top Interview Questions/155.Min Stack.cpp
@@ -0,0 +1,37 @@
1
+class MinStack {
2
+public:
3
+ /** initialize your data structure here. */int arr[9999],min,tp;
4
+ MinStack() {
5
+ tp=-1;
6
+ }
7
+
8
+ void push(int x) {
9
+ tp++;
10
+ arr[tp]=x;
11
+ cout<<tp<<" push\n";
12
13
14
15
+ void pop() {
16
+ --tp;
17
+ cout<<tp<<" pop\n";
18
19
20
21
+ int top() {
22
+ cout<<tp<<" top\n";
23
+ return arr[tp];
24
25
26
27
+ int getMin() {
28
+ cout<<tp<<" min\n";
29
+ min = INT_MAX;
30
+ for(int i = 0;i<=tp;i++)
31
+ {
32
+ if(min>arr[i])
33
+ min = arr[i];
34
35
+ return min;
36
37
+};
0 commit comments