• 0

    Here's my thought process of the code. #(number) to follow along

    #1: if list of numbers is empty, or the length of numbers is 1 (impossible to have duplicates), return False
    #2: sets contain no duplicates, so if sorted set of nums is not equal to the original sorted(nums), return True
    #3: if all else fails we return False

    class Solution(object):
        def containsDuplicate(self, nums):
            if not nums or len(nums) == 1: #1
                return False
            if sorted(nums) != sorted(list(set(nums))): #2
                return True
            return False #3

Log in to reply

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