class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
if(len(nums) == 0):
return []
nums.sort()
tmp = []
res = []
flag = [0] * len(nums)
def backtrace():
if (len(tmp) == len(nums)):
res.append(tmp.copy())
return
for i in range(len(nums)):
if flag[i] == 1:
continue
if(i > 0 and nums[i] == nums[i-1] and flag[i-1] == False):
continue
tmp.append(nums[i])
flag[i] = 1
backtrace()
flag[i] = 0
tmp.pop()
return
backtrace()
return res
#47. 全排列 II
最新推荐文章于 2023-12-04 16:25:04 发布