Skip to content

Commit 44dc89e

Browse files
committed
456-java-solution
1 parent d49b16e commit 44dc89e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

java/456-132-Pattern.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
/*
3+
* Mono Stack
4+
* TC: O(n)
5+
* SC: O(n)
6+
*/
7+
public boolean find132pattern(int[] nums) {
8+
int n = nums.length;
9+
Stack<Integer> st = new Stack<>();
10+
int secondMax = Integer.MIN_VALUE;
11+
12+
for (int x = n - 1; x >= 0; x--) {
13+
if (nums[x] < secondMax)
14+
return true;
15+
16+
while (!st.isEmpty() && st.peek() < nums[x])
17+
secondMax = Math.max(st.pop(), secondMax);
18+
19+
st.push(nums[x]);
20+
}
21+
return false;
22+
}
23+
}

0 commit comments

Comments
 (0)