class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
ans = []
n = len(nums)
nums.sort()
def dfs(cur, nums):
if cur >= n:
ans.append(nums[:])
return
for i in range(cur, n):
if i != cur and nums[cur] == nums[i]: continue
nums[cur], nums[i] = nums[i], nums[cur]
dfs(cur+1, nums[:])
# nums[cur], nums[i] = nums[i], nums[cur]
dfs(0, nums[:])
return ans