public int longestConsecutive(int[] num) {
        HashSet<Integer> hs = new HashSet<Integer>();
        for(int n : num) hs.add(n);
        	
        int ans = 0;
        for(int n : num){
        	if(hs.contains(n)){
        		int temp = findConsecutive(hs, n, true) + findConsecutive(hs, n, false) + 1;
        		hs.remove(n);
        		if(temp > ans) ans = temp;
        	}
        }
        return ans;
    }