456. 132 Pattern Medium

@problem@discussion
#Array#Binary Search#Stack#Monotonic Stack#Ordered Set



1/**
2 * [456] 132 Pattern
3 *
4 * Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].
5 * Return true if there is a 132 pattern in nums, otherwise, return false.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [1,2,3,4]
10 * Output: false
11 * Explanation: There is no 132 pattern in the sequence.
12 * 
13 * Example 2:
14 * 
15 * Input: nums = [3,1,4,2]
16 * Output: true
17 * Explanation: There is a 132 pattern in the sequence: [1, 4, 2].
18 * 
19 * Example 3:
20 * 
21 * Input: nums = [-1,3,2,0]
22 * Output: true
23 * Explanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	n == nums.length
29 * 	1 <= n <= 2 * 10^5
30 * 	-10^9 <= nums[i] <= 10^9
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/132-pattern/
36// discuss: https://leetcode.com/problems/132-pattern/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn find132pattern(nums: Vec<i32>) -> bool {
42        false
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_456() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.