update 0090.子集II:替换 go 代码,修改 python 的markdown语法错误

This commit is contained in:
Yuhao Ju
2022-12-09 16:52:22 +08:00
committed by GitHub
parent 6a9a695a2c
commit 26e8174687

View File

@ -261,10 +261,10 @@ class Solution:
self.path.pop() self.path.pop()
``` ```
### Python3 #### Python3
不使用used数组 不使用used数组
```python3 ```python
class Solution: class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]: def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
res = [] res = []
@ -291,7 +291,7 @@ class Solution:
``` ```
使用used数组 使用used数组
```python3 ```python
class Solution: class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]: def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
result = [] result = []
@ -315,26 +315,30 @@ class Solution:
### Go ### Go
```Go ```Go
var res[][]int var (
func subsetsWithDup(nums []int)[][]int { path []int
res=make([][]int,0) res [][]int
sort.Ints(nums) )
dfs([]int{},nums,0) func subsetsWithDup(nums []int) [][]int {
return res 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) func dfs(nums []int, start int) {
for i:=start;i<len(num);i++{ tmp := make([]int, len(path))
if i>start&&num[i]==num[i-1]{ copy(tmp, path)
continue res = append(res, tmp)
}
temp=append(temp,num[i]) for i := start; i < len(nums); i++ {
dfs(temp,num,i+1) if i != start && nums[i] == nums[i-1] {
temp=temp[:len(temp)-1] continue
} }
path = append(path, nums[i])
dfs(nums, i+1)
path = path[:len(path)-1]
}
} }
``` ```