Created
April 6, 2019 04:14
-
-
Save nma/68b72992e7b87908fba674b8e719a280 to your computer and use it in GitHub Desktop.
Permutations Backtracking
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 backtracking(permutations, path, options): | |
if len(path) == len(options): | |
permutations.append(path[:]) | |
else: | |
for option in options: | |
if option in path: | |
continue | |
path.append(option) | |
backtracking(permutations, path, options) | |
path.pop() | |
backtracking(result, [], nums) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment