Created
August 26, 2021 12:13
-
-
Save goish135/5ef03fa846ed03a8149126de8a5f3b42 to your computer and use it in GitHub Desktop.
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]]: | |
ans = [] | |
# base | |
if len(nums)==1: | |
return [nums[:]] | |
for i in range(len(nums)): # counter | |
tmp=nums.pop(0) | |
res=self.permute(nums) | |
for j in res: | |
j.append(tmp) | |
ans.extend(res) | |
nums.append(tmp) | |
return ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment