456. 132 模式

  1. class Solution {
  2. public boolean find132pattern(int[] nums) {
  3. if (nums.length < 3)
  4. return false;
  5. Deque<Integer> stack = new LinkedList<>();
  6. int k = Integer.MIN_VALUE;
  7. for (int i = nums.length - 1; i >= 0; i--) {
  8. if (nums[i] < k)
  9. return true;
  10. while (!stack.isEmpty() && stack.peek() < nums[i]) {
  11. k = Math.max(k, stack.pop());
  12. }
  13. stack.push(nums[i]);
  14. }
  15. return false;
  16. }
  17. }