Skip to content

Latest commit

 

History

History
18 lines (18 loc) · 557 Bytes

47.md

File metadata and controls

18 lines (18 loc) · 557 Bytes
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