mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 02:53:31 +08:00
Merge pull request #1519 from JakeVander/master
添加 0090.子集II.md Python3版本
This commit is contained in:
@ -261,6 +261,33 @@ class Solution:
|
||||
self.path.pop()
|
||||
```
|
||||
|
||||
### Python3
|
||||
```python3
|
||||
class Solution:
|
||||
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
|
||||
res = []
|
||||
path = []
|
||||
nums.sort() # 去重需要先对数组进行排序
|
||||
|
||||
def backtracking(nums, startIndex):
|
||||
# 终止条件
|
||||
res.append(path[:])
|
||||
if startIndex == len(nums):
|
||||
return
|
||||
|
||||
# for循环
|
||||
for i in range(startIndex, len(nums)):
|
||||
# 数层去重
|
||||
if i > startIndex and nums[i] == nums[i-1]: # 去重
|
||||
continue
|
||||
path.append(nums[i])
|
||||
backtracking(nums, i+1)
|
||||
path.pop()
|
||||
|
||||
backtracking(nums, 0)
|
||||
return res
|
||||
```
|
||||
|
||||
### Go
|
||||
|
||||
```Go
|
||||
|
Reference in New Issue
Block a user