public int longestConsecutive(int[] num) {
        // {100, 4, 200, 2, 1, 3}
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i : num) {
            map.put(i, 0);
        }

        int max = 1;
        for (int i = 0; i < num.length; i++) {
            int crt = num[i];
            if (!map.containsKey(crt)) {
                continue;
            }

            map.remove(crt);

            int tmp1 = crt + 1;
            while (map.containsKey(tmp1)) {
                map.remove(tmp1);
                tmp1++;
            }

            int tmp2 = crt - 1;
            while (map.containsKey(tmp2)) {
                map.remove(tmp2);
                tmp2--;
            }
            max = Math.max(max, tmp1 - tmp2 - 1);
        }

        return max;
    }