public int longestConsecutive(int[] num) {
        int n = num.length;
        if (n<=1) return n;
        
        HashSet<Integer> set = new HashSet<Integer>();
        for(int i = 0; i < n; i++){
            set.add(num[i]);
        }
        
        int l = 1;
        while(!set.isEmpty()){
            int start = set.iterator().next();
            int end = start+1;
            while(true){
                if(!set.contains(start)) break;
                set.remove(start);
                start--;
                
            }
            while(true){
                if(!set.contains(end)) break;
                set.remove(end);
                end++;
                
            }
            System.out.println(start + ", " + end);
            l =  l > end-start-1 ? l : end-start-1;
        }
        return l;
    }