Merge pull request #1702 from tlylt/update-0090

Update problems/0090.子集II.md
This commit is contained in:
程序员Carl
2022-10-25 09:55:17 +08:00
committed by GitHub

View File

@ -262,6 +262,8 @@ class Solution:
```
### Python3
不使用used数组
```python3
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
@ -288,6 +290,28 @@ class Solution:
return res
```
使用used数组
```python3
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
result = []
path = []
nums.sort()
used = [0] * len(nums)
def backtrack(nums, startIdx):
result.append(path[:])
for i in range(startIdx, len(nums)):
if i > startIdx and nums[i] == nums[i-1] and used[i-1] == 0:
continue
used[i] = 1
path.append(nums[i])
backtrack(nums, i+1)
path.pop()
used[i] = 0
backtrack(nums, 0)
return result
```
### Go
```Go
@ -526,7 +550,7 @@ func subsetsWithDup(_ nums: [Int]) -> [[Int]] {
### Scala
不使用userd数组:
不使用used数组:
```scala
object Solution {