• + 3 comments

    It's both. The call to contains() on colors will be O(1) for a HashSet versus O(n) for a List, and you won't store duplicates. The listing above can be improved by using the output of remove instead of calling contains first. You can also add directly to the Set when reading from Stdin rather than storing values first and iterating through them.