Easy python code using dictionary


  • 0
    G
    class Solution(object):
        def findDuplicate(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            a={}
            for i in range(0,len(nums)):
                if nums[i] in a:
                    return nums[i]
                else:
                    a[nums[i]]=i

Log in to reply
 

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