Advertisement
haikid

Untitled

Nov 23rd, 2022
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. class Solution:
  2. def permute(self, nums: List[int]) -> List[List[int]]:
  3. def helper(currIndex, currPermutation):
  4. if len(currPermutation) == len(nums):
  5. res.append(currPermutation[:])
  6. return
  7. if currIndex >= len(nums):
  8. return
  9.  
  10. for i in range(currIndex, len(nums)):
  11. nums[currIndex], nums[i] = nums[i], nums[currIndex]
  12. currPermutation.append(nums[currIndex])
  13. helper(currIndex + 1, currPermutation)
  14. del currPermutation[-1]
  15. nums[currIndex], nums[i] = nums[i], nums[currIndex]
  16.  
  17. res = []
  18. helper(0, [])
  19. return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement