java.lang.Object
g2301_2400.s2369_check_if_there_is_a_valid_partition_for_the_array.Solution

public class Solution extends Object
2369 - Check if There is a Valid Partition For The Array.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p> <p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditions:</p> <ol> <li>The subarray consists of <strong>exactly</strong> <code>2</code> equal elements. For example, the subarray <code>[2,2]</code> is good.</li> <li>The subarray consists of <strong>exactly</strong> <code>3</code> equal elements. For example, the subarray <code>[4,4,4]</code> is good.</li> <li>The subarray consists of <strong>exactly</strong> <code>3</code> consecutive increasing elements, that is, the difference between adjacent elements is <code>1</code>. For example, the subarray <code>[3,4,5]</code> is good, but the subarray <code>[1,3,5]</code> is not.</li> </ol> <p>Return <code>true</code> <em>if the array has <strong>at least</strong> one valid partition</em>. Otherwise, return <code>false</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [4,4,4,5,6]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> The array can be partitioned into the subarrays [4,4] and [4,5,6]. This partition is valid, so we return true.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,1,1,2]</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> There is no valid partition for this array.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>6</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • validPartition

      public boolean validPartition(int[] nums)