1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| class Solution { public boolean find132pattern(int[] nums) { int[] leftMinArray = new int[nums.length]; leftMinArray[0] = Integer.MAX_VALUE; for (int i = 1; i < leftMinArray.length; i++) { leftMinArray[i] = Math.min(leftMinArray[i - 1], nums[i - 1]); }
Stack<Integer> decreaseStack = new Stack<>(); for (int j = nums.length - 1; j > 0; j--) { int numK = Integer.MIN_VALUE; while (!decreaseStack.isEmpty() && nums[j] > decreaseStack.peek()) { numK = decreaseStack.pop(); } if (numK > leftMinArray[j]) { return true; } decreaseStack.push(nums[j]); }
return false; } }
|