python - permutations


  • 0
    S
    class Solution(object):
        def do_permute(self, nums, prefix, answer):
    
            if not nums:
                answer.append(prefix)
            
            for num in nums:
                self.do_permute(nums - set([num]), prefix + [num], answer)
            
            return answer
            
        def permute(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            return self.do_permute(set(nums), [], [])
    

Log in to reply
 

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