这是我的代码:
package src
func Subsets(nums []int) [][]int {
var sets = make([][]int, 0)
var t = make([]int, 0)
sets = append(sets, t)
for i := 0; i < len(nums); i++ {
for _, v := range sets {
t = append(v, nums[i])
sets = append(sets, t) }
}
return sets
}
测试数据是[]int{1,2,3,4,5}
我调试它。发现:
计算sets[22]时,sets[15]由[]int{1,2,3,4}变为[]int{1,2,3,5}
发生了什么。
哔哔one
相关分类