forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0090.py
More file actions
21 lines (19 loc) · 644 Bytes
/
0090.py
File metadata and controls
21 lines (19 loc) · 644 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution:
def subsetsWithDup(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
nums.sort()
result = list()
self._subsetsWithDup(nums, 0, list(), result)
return result
def _subsetsWithDup(self, nums, index, path, result):
result.append(path.copy())
for i in range(index, len(nums)):
if index < i and nums[i] == nums[i - 1]:# add
continue
self._subsetsWithDup(nums, i + 1, path + [nums[i]], result)
if __name__ == '__main__':
nums = [1, 2, 2]
print(Solution().subsetsWithDup(nums))