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