Skip to content

Commit 6e270a6

Browse files
refactor 155
1 parent cd17ac2 commit 6e270a6

File tree

1 file changed

+3
-7
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-7
lines changed

src/main/java/com/fishercoder/solutions/_155.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,10 @@ public void push(int x) {
4848
}
4949

5050
public void pop() {
51-
if (min == stack.peek()) {
52-
stack.pop();
51+
/**if the value on the top of the stack happens to be the current minimum, we'll pop twice and change
52+
* the current min value to be the last min value */
53+
if (min == stack.pop()) {
5354
min = stack.pop();
54-
} else {
55-
stack.pop();
56-
}
57-
if (stack.isEmpty()) {
58-
min = Integer.MAX_VALUE;
5955
}
6056
}
6157

0 commit comments

Comments
 (0)