Created
February 15, 2020 02:19
-
-
Save HauptJ/0fbb657f18cc366dc88ac2236ae63486 to your computer and use it in GitHub Desktop.
46. Permutations - https://leetcode.com/problems/permutations/
This file contains 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]]: | |
list = [] | |
tempList = [] | |
def backtrack(list, tempList, nums): | |
if len(tempList) == len(nums): | |
list.append(tempList) | |
else: | |
for i in range(0, len(nums), 1): | |
if nums[i] in tempList: | |
continue | |
else: | |
tempList.append(nums[i]) | |
backtrack(list, tempList, nums) | |
del tempList[(len(tempList)-1)] | |
backtrack(list, tempList, nums) | |
return list | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment