Last active
August 26, 2020 04:00
-
-
Save nma/253cae4dd10da7dd6a0d79e4fb6b15ea to your computer and use it in GitHub Desktop.
Permutations Recusive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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