labels: Arrays, Hashing, Easy
Time Completed: 1:12
Link to problem: 217. Contains Duplicate
- Loop through nums
- Check if num is in hashmap, if it is return True, else add to hashmap
- Use default python constructor for hashmap
- Compare size of hashmap and size of nums. If it's the same size then that means all numbers are unique, no duplicate, return False. Otherwise return true
- Super easy. Just use a hashmap and remember its properties.
def containsDuplicate(self, nums):
hashmap = set(nums)
if len(hashmap) == len(nums):
return False
return True