mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Merge pull request #1702 from tlylt/update-0090
Update problems/0090.子集II.md
This commit is contained in:
@ -261,7 +261,9 @@ class Solution:
|
|||||||
self.path.pop()
|
self.path.pop()
|
||||||
```
|
```
|
||||||
|
|
||||||
### Python3
|
### Python3
|
||||||
|
|
||||||
|
不使用used数组
|
||||||
```python3
|
```python3
|
||||||
class Solution:
|
class Solution:
|
||||||
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
|
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
|
||||||
@ -288,6 +290,28 @@ class Solution:
|
|||||||
return res
|
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
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
@ -526,7 +550,7 @@ func subsetsWithDup(_ nums: [Int]) -> [[Int]] {
|
|||||||
|
|
||||||
### Scala
|
### Scala
|
||||||
|
|
||||||
不使用userd数组:
|
不使用used数组:
|
||||||
|
|
||||||
```scala
|
```scala
|
||||||
object Solution {
|
object Solution {
|
||||||
|
Reference in New Issue
Block a user