Skip to content

Instantly share code, notes, and snippets.

@Dounx
Created August 30, 2019 15:55
Show Gist options
  • Save Dounx/ce97bd5553ece289b2adc410423a04d5 to your computer and use it in GitHub Desktop.
Save Dounx/ce97bd5553ece289b2adc410423a04d5 to your computer and use it in GitHub Desktop.
78. 子集
// [9,0,3,5,7]
// When num = 9, size = 16, i = 7, there will be a strange issue:
// ans[15][3] 7 -> 9
func subsets(nums []int) [][]int {
sort.Ints(nums)
// fmt.Println(nums)
ans := make([][]int, 0)
ans = append(ans, []int{})
for _, num := range(nums) {
size := len(ans)
for i := 0; i < size; i++ {
ans = append(ans, append(ans[i], num))
// fmt.Println(len(ans) - 1, num, ans[i], append(ans[i], num))
}
}
// fmt.Println(ans[15])
return ans
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment