public static int longetConsecutive(int[] num) {
        if (num == null || num.length == 0) {
            return 0;
        }

        HashSet<Integer> set = new HashSet<Integer>();

        for (int i = 0; i < num.length; i++) {
            set.add(num[i]);
        }

        int res = 0;

        for (int i = 0; i < num.length; i++) {
            if (set.contains(num[i])) {
                set.remove(num[i]);

                int tmp = 1;
                int next = num[i] + 1;
                while (set.contains(next)) {
                    set.remove(next);
                    next++;
                    tmp++;
                }

                next = num[i] - 1;
                while (set.contains(next)) {
                    set.remove(next);
                    next--;
                    tmp++;
                }

                res = Math.max(tmp, res);
            }
        }

        return res;
    }