Skip to content

Instantly share code, notes, and snippets.

@goish135
Created August 26, 2021 19:05
Show Gist options
  • Save goish135/3bda8cfc7b005c330d1d79cdbdc73a8c to your computer and use it in GitHub Desktop.
Save goish135/3bda8cfc7b005c330d1d79cdbdc73a8c to your computer and use it in GitHub Desktop.
class Solution:
def permuteUnique(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.permuteUnique(nums)
for j in res:
j.append(tmp)
another_ = []
for re in res:
if re not in ans:
another_.append(re)
ans.extend(another_)
nums.append(tmp)
return ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment