8000
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 9728e28 commit 80fdd83Copy full SHA for 80fdd83
practice/problems/132_pattern/solution.java
@@ -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