# nums = list class Solution: def permute(self, nums: List[int]) -> List[List[int]]: res = [] self.dfs(nums, [], res) return res def dfs(self, nums, path, res): if not nums: res.append(path) #return # backtracking for i in range(len(nums)): self.dfs(nums[:i]+nums[i+1:], path+[nums[i]], res)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter