removeDuplicates: O(n)