Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def permute(self, nums: List[int]) -> List[List[int]]:
- # Base Case
- if not len(nums):
- return [[]]
- result = []
- for i in range(len(nums)):
- # let's assume it returns a list of lists
- # of all possible permutations except the
- # element in question/iterating over
- permutations = self.permute(nums[:i] + nums[i+1:])
- # add the element in question as a leading element
- # to the generated permutations and add each list
- # to the final result
- for j in range(len(permutations)):
- permutations[j] = [nums[i]] + permutations[j]
- # Gather final result and add list of lists to the
- # to the accumulator result variable
- result += permutations
- return result
Advertisement
Add Comment
Please, Sign In to add comment