beats 90.22%, in python, without swap


  • 0
    class Solution(object):
        def findDuplicates(self, nums):
            res = []
            for item in nums:
                item = abs(item)
                if nums[item - 1] < 0:
                    res.append(item)
                else:
                    nums[item - 1] *= -1
            return res
    

Log in to reply
 

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