334. Increasing Triplet Subsequence Medium
1/**
2 * [334] Increasing Triplet Subsequence
3 *
4 * Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices exists, return false.
5 *
6 * Example 1:
7 *
8 * Input: nums = [1,2,3,4,5]
9 * Output: true
10 * Explanation: Any triplet where i < j < k is valid.
11 *
12 * Example 2:
13 *
14 * Input: nums = [5,4,3,2,1]
15 * Output: false
16 * Explanation: No triplet exists.
17 *
18 * Example 3:
19 *
20 * Input: nums = [2,1,5,0,4,6]
21 * Output: true
22 * Explanation: The triplet (3, 4, 5) is valid because nums[3] == 0 < nums[4] == 4 < nums[5] == 6.
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= nums.length <= 5 * 10^5
28 * -2^31 <= nums[i] <= 2^31 - 1
29 *
30 *
31 * Follow up: Could you implement a solution that runs in O(n) time complexity and O(1) space complexity?
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/increasing-triplet-subsequence/
36// discuss: https://leetcode.com/problems/increasing-triplet-subsequence/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn increasing_triplet(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_334() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.