simple python DFS


  • 0
    P
    class Solution(object):
        def __init__(self):
            self.res = []
        def dfs(self,nums,path):
            if not nums:
                self.res.append(path)
            for i in range(len(nums)):
                if i != 0 and nums[i] == nums[i-1]:
                    continue
                self.dfs(nums[:i]+nums[i+1:],path+[nums[i]])
                    
        def permuteUnique(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            nums.sort()
            self.dfs(nums,[])
            return self.res
    

  • 0
    K

    Why do you use nums[:i]+nums[i+1:] insted of nums?


Log in to reply
 

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