8000 Sync LeetCode submission - 132 Pattern (java) · thatbeautifuldream/leetcode-sync@80fdd83 · GitHub
[go: up one dir, main page]

Skip to content

Commit 80fdd83

Browse files
thatbeautifuldream< 8000 a class="Box-sc-g0xbh4-0 dkaFxu prc-Link-Link-85e08" data-muted="true" muted="" href="/thatbeautifuldream/leetcode-sync/commits?author=thatbeautifuldream" aria-label="commits by thatbeautifuldream" data-hovercard-url="/users/thatbeautifuldream/hovercard">thatbeautifuldream
committed
Sync LeetCode submission - 132 Pattern (java)
1 parent 9728e28 commit 80fdd83

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Solution {
2+
public boolean find132pattern(int[] nums) {
3+
if (nums == null || nums.length < 3) return false;
4+
Deque<Integer> stack = new ArrayDeque<Integer>();
5+
int len = nums.length;
6+
int maxSecond = Integer.MIN_VALUE;
7+
for (int i = len - 1; i >= 0; i--) {
8+
if(nums[i] < maxSecond) {
9+
return true;
10+
}
11+
while(!stack.isEmpty() && nums[i] > stack.peek()) {
12+
maxSecond = stack.pop();
13+
}
14+
stack.push(nums[i]);
15+
}
16+
return false;
17+
18+
}
19+
}

0 commit comments

Comments
 (0)
0