2369. Check if There is a Valid Partition For The Array Medium
1/**
2 * [2369] Check if There is a Valid Partition For The Array
3 *
4 * You are given a 0-indexed integer array nums. You have to partition the array into one or more contiguous subarrays.
5 * We call a partition of the array valid if each of the obtained subarrays satisfies one of the following conditions:
6 * <ol>
7 * The subarray consists of exactly 2 equal elements. For example, the subarray [2,2] is good.
8 * The subarray consists of exactly 3 equal elements. For example, the subarray [4,4,4] is good.
9 * The subarray consists of exactly 3 consecutive increasing elements, that is, the difference between adjacent elements is 1. For example, the subarray [3,4,5] is good, but the subarray [1,3,5] is not.
10 * </ol>
11 * Return true if the array has at least one valid partition. Otherwise, return false.
12 *
13 * Example 1:
14 *
15 * Input: nums = [4,4,4,5,6]
16 * Output: true
17 * Explanation: The array can be partitioned into the subarrays [4,4] and [4,5,6].
18 * This partition is valid, so we return true.
19 *
20 * Example 2:
21 *
22 * Input: nums = [1,1,1,2]
23 * Output: false
24 * Explanation: There is no valid partition for this array.
25 *
26 *
27 * Constraints:
28 *
29 * 2 <= nums.length <= 10^5
30 * 1 <= nums[i] <= 10^6
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/check-if-there-is-a-valid-partition-for-the-array/
36// discuss: https://leetcode.com/problems/check-if-there-is-a-valid-partition-for-the-array/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn valid_partition(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_2369() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.