package leetcode;

/**
 * https://leetcode.com/problems/hand-of-straights/
 */
public class Problem846 {
    public boolean isNStraightHand(int[] hand, int W) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem846 prob = new Problem846();
    }
}

@@ -12,16 +12,71 @@
 tcode;%0A%0A
+import java.util.Map.Entry;%0Aimport java.util.TreeMap;%0A%0A
 /**%0A * h
@@ -221,132 +221,1192 @@
     
-// TODO%0A        return false;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem846 prob = new Problem846()
+TreeMap%3CInteger, Integer%3E map = new TreeMap%3C%3E();%0A        for (int i = 0; i %3C hand.length; i++) %7B%0A            if (!map.containsKey(hand%5Bi%5D)) %7B%0A                map.put(hand%5Bi%5D, 1);%0A            %7D else %7B%0A                map.put(hand%5Bi%5D, map.get(hand%5Bi%5D) + 1);%0A            %7D%0A        %7D%0A        boolean result = true;%0A        while (!map.isEmpty()) %7B%0A            Entry%3CInteger, Integer%3E first = map.firstEntry();%0A            int prevKey = first.getKey();%0A            int newPrevVal = first.getValue() - 1;%0A            if (newPrevVal == 0) %7B%0A                map.remove(prevKey);%0A            %7D else %7B%0A                map.put(prevKey, newPrevVal);%0A            %7D%0A            for (int i = 0; i %3C W - 1; i++) %7B%0A                int curKey = prevKey + 1;%0A                if (!map.containsKey(curKey)) %7B%0A                    return false;%0A                %7D%0A                int curVal = map.get(curKey);%0A                int newCurValue = curVal - 1;%0A                if (newCurValue == 0) %7B%0A                    map.remove(curKey);%0A                %7D else %7B%0A                    map.put(curKey, newCurValue);%0A                %7D%0A                prevKey = curKey;%0A            %7D%0A        %7D%0A        return result
 ;%0A  

Solve problem 846