1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| func subsets(nums []int) [][]int { result := [][]int{} curr := []int{}
var dfs func(int) dfs = func(i int){ if i >= len(nums) { result = append(result, append([]int{}, curr...)) return }
curr = append(curr, nums[i]) dfs(i + 1) curr = curr[:len(curr)-1] dfs(i + 1) }
dfs(0)
return result }
|