subsets
subsets.go 源码
package main
//子集
func subsets(nums []int) [][]int {
var res [][]int
subsetsHelper(nums, 0, []int{}, &res)
return res
}
func subsetsHelper(nums []int, k int, data []int, res *[][]int) {
temp := make([]int, len(data))
copy(temp, data)
*res = append(*res, temp)
for i := k; i < len(nums); i++ {
data = append(data, nums[i])
subsetsHelper(nums, i+1, data, res)
data = data[:len(data)-1]
}
}
你可能感兴趣的文章
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦