Simplify the implementation by removing second HashSet, use only one HashSet to keep track of visited numbers.