Skip to content

Instantly share code, notes, and snippets.

@goish135
Created August 26, 2021 12:13
Show Gist options
  • Save goish135/5ef03fa846ed03a8149126de8a5f3b42 to your computer and use it in GitHub Desktop.
Save goish135/5ef03fa846ed03a8149126de8a5f3b42 to your computer and use it in GitHub Desktop.
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