132 Pattern LeetCode solution in Java
1class Solution {2public boolean find132pattern(int[] nums) {3int min = Integer.MIN_VALUE;4int peak = nums.length;5for (int i = nums.length - 1; i >= 0; i--) {6// We find a "132" pattern if nums[i] < min, so return true...7if (nums[i] < min) return true;8// If peak < nums.length & nums[i] is greater than the peak element...9while (peak < nums.length && nums[i] > nums[peak]) min = nums[peak++];10// Now we have nums[i] <= nums[peak]11// We push nums[i] to the "stack"12peak--;13nums[peak] = nums[i];14}15return false;16}17}