Dashboard Temp Share Shortlinks Frames API

HTMLify

LeetCode - Permutations - Python
Views: 353 | Author: abh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Solution:
    def permute(self, nums: List[int]) -> List[List[int]]:
        if len(nums) == 1: return [[nums[0]]]
        combs = []
        for n in nums:
            tnums = nums.copy()
            tnums.remove(n)
            scombs =  self.permute(tnums)
            for scomb in scombs:
                combs.append([n]+scomb)
        return combs