牛客题霸 NC27 集合的所有子集
生活随笔
收集整理的這篇文章主要介紹了
牛客题霸 NC27 集合的所有子集
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
https://www.nowcoder.com/practice/c333d551eb6243e0b4d92e37a06fbfc9
解決方案
Go
版本一
func subsets(A []int) [][]int {// write code heren := len(A)if n == 0 {return [][]int{{}}}res := subsets(A[:n-1])ln := len(res)for i := 0; i < ln; i++ {// 深拷貝tmp := make([]int, len(res[i]))copy(tmp, res[i])res = append(res, append(tmp, A[n-1]))}return res }參考文章
總結(jié)
以上是生活随笔為你收集整理的牛客题霸 NC27 集合的所有子集的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牛客题霸 NC26 括号生成
- 下一篇: 牛客题霸 NC28 最小覆盖子串