mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
添加 0090.子集 python3版本
添加 0090.子集 python3版本
This commit is contained in:
@ -208,7 +208,23 @@ class Solution {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
```python3
|
||||||
|
class Solution:
|
||||||
|
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
|
||||||
|
res = [] #存放符合条件结果的集合
|
||||||
|
path = [] #用来存放符合条件结果
|
||||||
|
def backtrack(nums,startIndex):
|
||||||
|
res.append(path[:])
|
||||||
|
for i in range(startIndex,len(nums)):
|
||||||
|
if i > startIndex and nums[i] == nums[i - 1]: #我们要对同一树层使用过的元素进行跳过
|
||||||
|
continue
|
||||||
|
path.append(nums[i])
|
||||||
|
backtrack(nums,i+1) #递归
|
||||||
|
path.pop() #回溯
|
||||||
|
nums = sorted(nums) #去重需要排序
|
||||||
|
backtrack(nums,0)
|
||||||
|
return res
|
||||||
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
```Go
|
```Go
|
||||||
|
Reference in New Issue
Block a user