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.
1 parent 4a2f991 commit b803e26Copy full SHA for b803e26
dart/0155-min-stack.dart
@@ -0,0 +1,28 @@
1
+class MinStack {
2
+ final List<int> stack = [];
3
+ final List<int> minStack = [];
4
+
5
+ MinStack();
6
7
+ void push(int val) {
8
+ stack.add(val);
9
+ if (minStack.isEmpty) {
10
+ minStack.add(val);
11
+ } else {
12
+ minStack.add(min(val, minStack.last));
13
+ }
14
15
16
+ void pop() {
17
+ stack.removeLast();
18
+ minStack.removeLast();
19
20
21
+ int top() {
22
+ return stack.last;
23
24
25
+ int getMin() {
26
+ return minStack.last;
27
28
+}
0 commit comments