-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLc456.java
More file actions
32 lines (30 loc) · 798 Bytes
/
Lc456.java
File metadata and controls
32 lines (30 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package leetcode;
import java.util.Arrays;
import java.util.Stack;
/**
* @author Kuma
* @date 2021年3月24日
* 456.132 模式
*/
public class Lc456 {
public boolean find132pattern(int[] nums) {
int n = nums.length;
int[] min = new int[n];
Arrays.fill(min,Integer.MAX_VALUE);
for (int i = 1; i < n; i++) {
min[i] = Math.min(min[i - 1], nums[i - 1]);
}
Stack<Integer> st = new Stack<>();
for (int i = n - 1; i > 0; i--) {
int minTmp = Integer.MIN_VALUE;
while (!st.isEmpty() && st.peek() < nums[i]){
minTmp = st.pop();
}
if (minTmp > min[i]){
return true;
}
st.push(nums[i]);
}
return false;
}
}