这道题实在是想不出来,看了题解区的大佬的题解,恍然大悟。
贴下大佬的代码:
class Solution { public boolean find132pattern(int[] nums) { int len = nums.length; int last = Integer.MIN_VALUE; Stack<Integer> stack = new Stack<>(); if(len < 3){ return false; } for(int i = len - 1; i >= 0; i--){ if(nums[i] < last){ return true; } while(!stack.isEmpty() && stack.peek() < nums[i]){ last = stack.pop(); } stack.push(nums[i]); } return false; } }