mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 07:35:35 +08:00
update 0090.子集II:替换 go 代码,修改 python 的markdown语法错误
This commit is contained in:
@ -261,10 +261,10 @@ class Solution:
|
||||
self.path.pop()
|
||||
```
|
||||
|
||||
### Python3
|
||||
#### Python3
|
||||
|
||||
不使用used数组
|
||||
```python3
|
||||
```python
|
||||
class Solution:
|
||||
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
|
||||
res = []
|
||||
@ -291,7 +291,7 @@ class Solution:
|
||||
```
|
||||
|
||||
使用used数组
|
||||
```python3
|
||||
```python
|
||||
class Solution:
|
||||
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
|
||||
result = []
|
||||
@ -315,26 +315,30 @@ class Solution:
|
||||
### Go
|
||||
|
||||
```Go
|
||||
var res[][]int
|
||||
func subsetsWithDup(nums []int)[][]int {
|
||||
res=make([][]int,0)
|
||||
sort.Ints(nums)
|
||||
dfs([]int{},nums,0)
|
||||
return res
|
||||
var (
|
||||
path []int
|
||||
res [][]int
|
||||
)
|
||||
func subsetsWithDup(nums []int) [][]int {
|
||||
path, res = make([]int, 0, len(nums)), make([][]int, 0)
|
||||
sort.Ints(nums)
|
||||
dfs(nums, 0)
|
||||
return res
|
||||
}
|
||||
func dfs(temp, num []int, start int) {
|
||||
tmp:=make([]int,len(temp))
|
||||
copy(tmp,temp)
|
||||
|
||||
res=append(res,tmp)
|
||||
for i:=start;i<len(num);i++{
|
||||
if i>start&&num[i]==num[i-1]{
|
||||
continue
|
||||
}
|
||||
temp=append(temp,num[i])
|
||||
dfs(temp,num,i+1)
|
||||
temp=temp[:len(temp)-1]
|
||||
}
|
||||
func dfs(nums []int, start int) {
|
||||
tmp := make([]int, len(path))
|
||||
copy(tmp, path)
|
||||
res = append(res, tmp)
|
||||
|
||||
for i := start; i < len(nums); i++ {
|
||||
if i != start && nums[i] == nums[i-1] {
|
||||
continue
|
||||
}
|
||||
path = append(path, nums[i])
|
||||
dfs(nums, i+1)
|
||||
path = path[:len(path)-1]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user