Skip to content

Instantly share code, notes, and snippets.

@nma
Last active August 26, 2020 04:00
Show Gist options
  • Save nma/253cae4dd10da7dd6a0d79e4fb6b15ea to your computer and use it in GitHub Desktop.
Save nma/253cae4dd10da7dd6a0d79e4fb6b15ea to your computer and use it in GitHub Desktop.
Permutations Recusive
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
result = []
def permute_helper(ans: List[int], cur: List[int], options: List[int]):
if len(options) == 0:
ans.append(cur)
else:
for index, choice in enumerate(options):
permute_helper(ans, cur + [choice], options[:index] + options[index + 1:])
permute_helper(result, [], nums)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment