java.lang.Object
g0601_0700.s0659_split_array_into_consecutive_subsequences.Solution

public class Solution extends Object
659 - Split Array into Consecutive Subsequences.<p>Medium</p> <p>You are given an integer array <code>nums</code> that is <strong>sorted in non-decreasing order</strong>.</p> <p>Determine if it is possible to split <code>nums</code> into <strong>one or more subsequences</strong> such that <strong>both</strong> of the following conditions are true:</p> <ul> <li>Each subsequence is a <strong>consecutive increasing sequence</strong> (i.e. each integer is <strong>exactly one</strong> more than the previous integer).</li> <li>All subsequences have a length of <code>3</code> <strong>or more</strong>.</li> </ul> <p>Return <code>true</code> <em>if you can split</em> <code>nums</code> <em>according to the above conditions, or</em> <code>false</code> <em>otherwise</em>.</p> <p>A <strong>subsequence</strong> of an array is a new array that is formed from the original array by deleting some (can be none) of the elements without disturbing the relative positions of the remaining elements. (i.e., <code>[1,3,5]</code> is a subsequence of <code>[1,2,3,4,5]</code> while <code>[1,3,2]</code> is not).</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,2,3,3,4,5]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> nums can be split into the following subsequences:</p> <p>[<strong>1</strong> , <strong>2</strong> , <strong>3</strong> ,3,4,5] &ndash;> 1, 2, 3</p> <p>[1,2,3, <strong>3</strong> , <strong>4</strong> , <strong>5</strong> ] &ndash;> 3, 4, 5</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,2,3,3,4,4,5,5]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> nums can be split into the following subsequences:</p> <p>[<strong>1</strong> , <strong>2</strong> , <strong>3</strong> ,3, <strong>4</strong> ,4, <strong>5</strong> ,5] &ndash;> 1, 2, 3, 4, 5</p> <p>[1,2,3, <strong>3</strong> ,4, <strong>4</strong> ,5, <strong>5</strong> ] &ndash;> 3, 4, 5</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [1,2,3,4,4,5]</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> It is impossible to split nums into consecutive increasing subsequences of length 3 or more.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>4</sup></code></li> <li><code>-1000 <= nums[i] <= 1000</code></li> <li><code>nums</code> is sorted in <strong>non-decreasing</strong> order.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isPossible

      public boolean isPossible(int[] nums)