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,25 +315,29 @@ class Solution:
### Go ### Go
```Go ```Go
var res[][]int var (
path []int
res [][]int
)
func subsetsWithDup(nums []int) [][]int { func subsetsWithDup(nums []int) [][]int {
res=make([][]int,0) path, res = make([]int, 0, len(nums)), make([][]int, 0)
sort.Ints(nums) sort.Ints(nums)
dfs([]int{},nums,0) dfs(nums, 0)
return res return res
} }
func dfs(temp, num []int, start int) {
tmp:=make([]int,len(temp))
copy(tmp,temp)
func dfs(nums []int, start int) {
tmp := make([]int, len(path))
copy(tmp, path)
res = append(res, tmp) res = append(res, tmp)
for i:=start;i<len(num);i++{
if i>start&&num[i]==num[i-1]{ for i := start; i < len(nums); i++ {
if i != start && nums[i] == nums[i-1] {
continue continue
} }
temp=append(temp,num[i]) path = append(path, nums[i])
dfs(temp,num,i+1) dfs(nums, i+1)
temp=temp[:len(temp)-1] path = path[:len(path)-1]
} }
} }
``` ```