Simple python solution


  • 0
    D

    """
    class Solution(object):
    def findDuplicates(self, nums):

        #regard value as index, set 1 if visited
        
        if not nums:
            return []
            
        res = []
        temp = [0] * len(nums)
        
        for i in nums:
            if temp[i-1] == 0:
                temp[i-1] = 1
            else:
                res.append(i)
        return res
    

    """


Log in to reply
 

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