v2 time O(n) space O(n) Accepted

two optimizations:

1) from HashMap.containsValue to HashMap.containsKey
2) from two passes to one pass

v1 is actually O(n^2) time complexity because HashMap.containsValue if O(n) instead of O(1)