Longest Consecutive Sequence
Because it requires O(n) complexity, we can not solve the problem by sorting the array first. Sorting takes at least O(nlogn) time.

remove the visited num in the hashset, so we can break out of the loop when maxlength is larger than the size of the hashset.