python solution in linear time using an array

  • -1
    class Solution(object):
        def findDuplicate(self, nums):
            :type nums: List[int]
            :rtype: int
            dups = [0] * (len(nums))
            for n in nums:
                dups[n] += 1
            for d in range(len(dups)):
                if dups[d] > 1:
                    return d

Log in to reply

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