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 370d175 + ba32672 commit f06c7dbCopy full SHA for f06c7db
src/stack/Problem155_MinStack.java
@@ -0,0 +1,32 @@
1
+package stack;
2
+
3
+import java.util.Stack;
4
5
+public class Problem155_MinStack {
6
7
+ class MinStack {
8
9
+ Stack<int[]> stack = new Stack<>();
10
11
+ /** initialize your data structure here. */
12
+ public MinStack() {
13
+ }
14
15
+ public void push(int x) {
16
+ int min = (stack.isEmpty()) ? x : Math.min(x, getMin());
17
+ stack.push(new int[] {x, min});
18
19
20
+ public void pop() {
21
+ stack.pop();
22
23
24
+ public int top() {
25
+ return stack.peek()[0];
26
27
28
+ public int getMin() {
29
+ return stack.peek()[1];
30
31
32
+}
0 commit comments