Class Solution
-
- All Implemented Interfaces:
public final class Solution2369 - Check if There is a Valid Partition For The Array\.
Medium
You are given a 0-indexed integer array
nums. You have to partition the array into one or more contiguous subarrays.We call a partition of the array valid if each of the obtained subarrays satisfies one of the following conditions:
The subarray consists of exactly
2equal elements. For example, the subarray[2,2]is good.The subarray consists of exactly
3equal elements. For example, the subarray[4,4,4]is good.The subarray consists of exactly
3consecutive increasing elements, that is, the difference between adjacent elements is1. For example, the subarray[3,4,5]is good, but the subarray[1,3,5]is not.
Return
trueif the array has at least one valid partition. Otherwise, returnfalse.Example 1:
Input: nums = 4,4,4,5,6
Output: true
Explanation: The array can be partitioned into the subarrays 4,4 and 4,5,6. This partition is valid, so we return true.
Example 2:
Input: nums = 1,1,1,2
Output: false
Explanation: There is no valid partition for this array.
Constraints:
<code>2 <= nums.length <= 10<sup>5</sup></code>
<code>1 <= numsi<= 10<sup>6</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleanvalidPartition(IntArray nums)-
-
Method Detail
-
validPartition
final Boolean validPartition(IntArray nums)
-
-
-
-