-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.py
34 lines (28 loc) · 944 Bytes
/
temp.py
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
26
27
28
29
30
31
32
33
34
from typing import List
class Solution:
def backtrack(self, nums, visited, track, ans):
if len(track) == len(nums):
ans.append(track.copy())
return
for i in range(len(nums)):
if visited[i]:
continue
if i > 0 and nums[i] == nums[i - 1] and not visited[i - 1]:
continue
visited[i] = 1
track.append(nums[i])
self.backtrack(nums, visited, track, ans)
track.pop()
visited[i] = 0
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
nums.sort()
visited = [0] * len(nums)
ans = []
self.backtrack(nums, visited, [], ans)
return ans
if __name__ == '__main__':
s = Solution()
print(s.permuteUnique([1, 1, 2]))
# print(s.maxLexicographical("1001"))
# print(s.quick_sort())
# print(s.insert([[1, 3], [6, 9]], [2, 5]))