We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents bdc70c6 + 1cdac98 commit fef3c9cCopy full SHA for fef3c9c
python/0047-permutations-ii.py
@@ -0,0 +1,25 @@
1
+import collections
2
+
3
4
+class Solution:
5
6
+ def permuteUnique(self, nums: List[int]) -> List[List[int]]:
7
+ result = []
8
+ counter = collections.Counter(nums)
9
10
+ def backtrack(perm, counter):
11
+ if len(perm) == len(nums):
12
+ result.append(perm.copy())
13
14
+ for n in counter:
15
+ if counter[n] == 0:
16
+ continue
17
+ perm.append(n)
18
+ counter[n] -= 1
19
+ backtrack(perm, counter)
20
+ perm.pop()
21
+ counter[n] += 1
22
23
+ backtrack([], counter)
24
25
+ return result
0 commit comments