LeetCode/주제별 보충

Hashmap: 217. Contains Duplicate

hyunkookim 2025. 1. 20. 18:23

217. Contains Duplicate

 

class Solution:
    def containsDuplicate(self, nums: List[int]) -> bool:
        hashmap = {}

        for num in nums:
            if num not in hashmap:
                hashmap[num]=1
            else:
                hashmap[num] += 1
                return True

        return False