My python O(N) time and O(1) space solution


  • 0
    P
    class Solution(object):
        def findDuplicate(self, nums):
            
            for i in range(0, len(nums)):
                
                if nums[abs(nums[i])] < 0:
                    return abs(nums[i])
                else:
                    nums[abs(nums[i])] *= -1
    

Log in to reply
 

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