Contains Duplicate

Link: Contains Duplicate
Type: Array
Difficulty: Easy

How to think of the problem

A hashmap allows us to insert with no duplicates

Solution

class Solution(object):
    def containsDuplicate(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        hash_map = {}
        for i,n in enumerate(nums):
            if n in hash_map:
                return True
            else:
                hash_map[n] = i
        return False