Problem :

https://leetcode.com/problems/permutations-ii/


My Solution :

class Solution:
def permuteUnique(self, nums):
def backtrack():
if len(path) == len(nums):
ret.append(path[:])
else:
for n in counter:
if counter[n]:
path.append(n)
counter[n] -= 1
backtrack()
path.pop()
counter[n] += 1

counter = {}
for n in nums:
counter[n] = counter.get(n, 0) + 1
path, ret = [], []
backtrack()
return ret
secret