Class Solution

java.lang.Object
g0801_0900.s0846_hand_of_straights.Solution

public class Solution extends Object
846 - Hand of Straights.<p>Medium</p> <p>Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size <code>groupSize</code>, and consists of <code>groupSize</code> consecutive cards.</p> <p>Given an integer array <code>hand</code> where <code>hand[i]</code> is the value written on the <code>i<sup>th</sup></code> card and an integer <code>groupSize</code>, return <code>true</code> if she can rearrange the cards, or <code>false</code> otherwise.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> hand = [1,2,3,6,2,3,4,7,8], groupSize = 3</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> Alice&rsquo;s hand can be rearranged as [1,2,3],[2,3,4],[6,7,8]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> hand = [1,2,3,4,5], groupSize = 4</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> Alice&rsquo;s hand can not be rearranged into groups of 4.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= hand.length <= 10<sup>4</sup></code></li> <li><code>0 <= hand[i] <= 10<sup>9</sup></code></li> <li><code>1 <= groupSize <= hand.length</code></li> </ul> <p><strong>Note:</strong> This question is the same as 1296: <a href="https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/" target="_top">https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/</a></p>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isNStraightHand

      public boolean isNStraightHand(int[] hand, int groupSize)