-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path47.py
More file actions
22 lines (21 loc) · 734 Bytes
/
Copy path47.py
File metadata and controls
22 lines (21 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
def BackTrack(m, per: list):
if m == n:
if per not in permutation:
permutation.append(per)
return per
for i in range(n):
if not visited[i]:
per.append(nums[i])
visited[i] = True
per = BackTrack(m + 1, per)
per = per[:-1]
visited[i] = False
return per
n = len(nums)
visited = [False for _ in range(n)]
per = []
permutation = []
BackTrack(0, [])
return list(set(tuple(k) for k in permutation))