46.全排列

class Solution:
    def permute(self, nums: List[int]) -> List[List[int]]:
        if len(nums) <= 1:
            return [nums]
        
        answer = []
        for i, num in enumerate(nums):
            n = nums[:i] + nums[i+1:]
            for y in self.permute(n):
                answer.append([num] + y)
                
        return answer

 

posted @ 2019-08-22 15:27  我叫郑小白  阅读(87)  评论(0编辑  收藏  举报