Leetcode: Contains duplicate
Given an array of
True if there is a duplicated number and
The simple most solution I could find was to use a
set and then see for every number if it is already contained in the set. A map would have worked as well. The time complexity for this is
O(n), assuming that the access to the hash set is
O(1), it takes only one iteration over the whole list.
Runtime: 439 ms, faster than 99.61% of Python3 online submissions for Contains Duplicate.
Memory Usage: 26 MB, less than 71.55% of Python3 online submissions for Contains Duplicate.