We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 4fee6df + 32c1628 commit bfa2851Copy full SHA for bfa2851
java/0456-132-Pattern.java
@@ -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