public int longestConsecutive(int[] num) {
		if(num == null || num.length == 0) return 0;
		
		int max = 0;
		Set<Integer> set = new HashSet<Integer>();
		for(int n : num) set.add(n);
		for(int n : num) {
			if(set.contains(n)) {
				set.remove(n);
				int res = 1 + search(n+1, set, true) + search(n-1, set, false);
				if(res > max) max = res;
			}
		}
		return max;
	}