Merge pull request #1519 from JakeVander/master

添加 0090.子集II.md Python3版本
This commit is contained in:
程序员Carl
2022-08-02 09:35:53 +08:00
committed by GitHub

View File

@ -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