Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def permute(self, nums: List[int]) -> List[List[int]]:
- def helper(currIndex, currPermutation):
- if len(currPermutation) == len(nums):
- res.append(currPermutation[:])
- return
- if currIndex >= len(nums):
- return
- for i in range(currIndex, len(nums)):
- nums[currIndex], nums[i] = nums[i], nums[currIndex]
- currPermutation.append(nums[currIndex])
- helper(currIndex + 1, currPermutation)
- del currPermutation[-1]
- nums[currIndex], nums[i] = nums[i], nums[currIndex]
- res = []
- helper(0, [])
- return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement