python - perm2 = perm1 + 1


  • 0
    S
    class Solution(object):
        def do_permute(self, nums, index, prefix, answer, seen):
    
            if not index:
                answer.add(prefix)
            
            if len(prefix) - 1 and prefix in seen:
                return
            
            seen.add(prefix)
            
            for i in index:
                self.do_permute(nums, index - set([i]), prefix + (nums[i],), answer, seen)
            
            return answer
    
        def permuteUnique(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            ret = self.do_permute(nums, set(range(len(nums))), tuple(), set(), set())
            answer = [list(t) for t in ret]
            return answer
    
    

Log in to reply
 

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