-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ47.py
More file actions
25 lines (22 loc) · 964 Bytes
/
Q47.py
File metadata and controls
25 lines (22 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from typing import List
class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
#solution 2:
return [[n]+p for n in set(nums) for p in self.permuteUnique(nums[:nums.index(n)]+nums[nums.index(n)+1:])] or [[]]
#solution 1:
# if len(nums)==1:
# return [nums]
# resultList = []
# def permuteHelper(result,remaining):
# if len(remaining)==1:
# if result+[remaining[0]] not in resultList:
# resultList.append(result+[remaining[0]])
# return
# else:
# for i in range(len(remaining)):
# permuteHelper(result+[remaining[i]],remaining[0:i]+remaining[i+1:])
# for i in range(len(nums)):
# permuteHelper([nums[i]],nums[0:i]+nums[i+1:])
# return resultList
if __name__ == '__main__':
print(Solution().permuteUnique([]))