@@ -0,0 +1,2121 @@
+package com.willlee.leetcode;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Apublic class Leetcode659 %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        Leetcode659 a = new Leetcode659();%0A        boolean possible = a.isPossible(new int%5B%5D %7B 1, 2, 3, 3, 4, 5 %7D);%0A        System.out.println(possible);%0A    %7D%0A%0A    public boolean isPossible(int%5B%5D nums) %7B%0A        HashMap%3CInteger, Integer%3E cnt = new HashMap%3C%3E(), tails = new HashMap%3C%3E();%0A        int len = nums.length;%0A        for (int i = 0; i %3C len; i++) %7B%0A            cnt.put(nums%5Bi%5D, cnt.getOrDefault(nums%5Bi%5D, 0) + 1);%0A        %7D%0A        int ele;%0A        for (int i = 0; i %3C len; i++) %7B%0A            ele = nums%5Bi%5D;%0A            if (cnt.get(ele) == 0) %7B%0A                continue;%0A            %7D else if (tails.containsKey(ele) && tails.get(ele) %3E 0) %7B%0A                cnt.put(ele, cnt.get(ele) - 1);%0A                tails.put(ele, tails.get(ele) - 1);%0A                tails.put(ele + 1, tails.getOrDefault(ele + 1, 0) + 1);%0A            %7D else if (cnt.containsKey(ele + 1) && cnt.get(ele + 1) %3E 0 && cnt.containsKey(ele + 2)%0A                    && cnt.get(ele + 2) %3E 0) %7B%0A                cnt.put(ele, cnt.get(ele) - 1);%0A                cnt.put(ele + 1, cnt.get(ele + 1) - 1);%0A                cnt.put(ele + 2, cnt.get(ele + 2) - 1);%0A                tails.put(ele + 3, tails.getOrDefault(ele + 3, 0) + 1);%0A            %7D else %7B%0A                return false;%0A            %7D%0A        %7D%0A        return true;%0A    %7D%0A%0A    public boolean isPossible1(int%5B%5D nums) %7B%0A        Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        for (int num : nums)%0A            map.put(num, map.getOrDefault(num, 0) + 1);%0A        for (int num : nums) %7B%0A            if (map.get(num) == 0)%0A                continue;%0A            int count = 0;%0A            while (map.containsKey(num) && map.get(num) %3E 0) %7B%0A                count++;%0A                if (count %3E 3 && map.get(num) %3C= map.get(num - 1))%0A                    break;%0A                map.put(num, map.get(num) - 1);%0A                num++;%0A            %7D%0A            if (count %3C 3)%0A                return false;%0A        %7D%0A        return true;%0A    %7D%0A%7D

add solution