update 0078.子集: 替换 go 代码

This commit is contained in:
Yuhao Ju
2022-12-08 21:30:41 +08:00
committed by GitHub
parent 78ae0f196c
commit 74ccecbdcd

View File

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