题目
https://leetcode-cn.com/problems/132-pattern/
思路
代码
class Solution {
public boolean find132pattern(int[] nums) {
int len=nums.length;
int maxK=Integer.MIN_VALUE;
Deque<Integer> stack=new LinkedList<>();
stack.push(nums[len-1]);
for(int i=len-2;i>=0;i--){
if(nums[i]<maxK){
return true;
}
while(!stack.isEmpty()&&stack.peek()<nums[i]){
maxK=stack.pop();
}
if(nums[i]>maxK){
stack.push(nums[i]);
}
}
return false;
}
}