Python solution with detailed explanation

  • 0


    Contains Duplicate

    • Use a set and complete the problem in a single pass
    • Or use a Counter class to test if there are duplicates.
    from collections import Counter        
    class Solution(object):
        def containsDuplicate(self, nums):
            :type nums: List[int]
            :rtype: bool
            return len(Counter(nums)) < len(nums)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.