数组子集golang版本
2023-08-20
1分钟阅读时长
数组子集
func subsets(nums []int) [][]int{
var res [][]int
var dfs func(index int,list []int)
dfs = func(index int, list []int) {
if index >= len(nums){
res = append(res, append([]int{},list...))
return
}
//不选index位置的元素Z
dfs(index+1,list)
list = append(list, nums[index])
dfs(index+1,list)
}
}