public int longestConsecutive(int[] num) {
        map.clear();
        heads.clear();

        for (int n : num) {
            if (map.containsKey(n))
                continue;

            ListNode node = new ListNode(n);
            map.put(n, node);

            node.next = null;
            if (map.containsKey(n + 1)) {
                node.next = map.get(n + 1);
                heads.remove(node.next);
            }

            if (map.containsKey(n - 1)) {
                map.get(n - 1).next = node;
            }
            else {
                heads.add(node);
            }
        }
        int max = 0;
        for (ListNode node : heads) {
            max = Math.max(max, size(node));
        }

        return 0;
    }