Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Leetcodde problem - https://leetcode.com/problems/permutations/
- perms = []
- def permHelper(nums, chosen):
- # print('permHelper(', nums , ', ' , chosen , ')', sep = "")
- # if-else
- if len(nums) == 0:
- print(chosen) # this line prints the permutation correctly
- perms.append(chosen) # but perms returning list of empty lists!
- else:
- for i in range(len(nums)):
- # choose
- n = nums[i]
- nums.remove(n)
- chosen.append(n)
- # explore
- permHelper(nums, chosen)
- # un-choose
- nums.insert(i, n)
- chosen.remove(n)
- # return perms
- class Solution:
- def permute(self, nums: List[int]) -> List[List[int]]:
- permHelper(nums, [])
- return perms
Add Comment
Please, Sign In to add comment