Created
August 26, 2021 19:05
-
-
Save goish135/3bda8cfc7b005c330d1d79cdbdc73a8c 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 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