最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

二叉樹基礎(chǔ)題難倒大廠程序員,我的粉絲都會(huì)寫吧

2023-07-14 01:20 作者:Acer在寫代碼  | 我要投稿

golang版本


/**

* Definition for a binary tree node.

* type TreeNode struct {

* Val int

* Left *TreeNode

* Right *TreeNode

* }

*/

// 遞歸解決

var res [][]int

func pathSum(root *TreeNode, target int) [][]int {

if root == nil {

return nil

}

res = [][]int{}

recurPath(target, root, []int{})

return res

}


func recurPath(target int, root *TreeNode, pb []int) {

if root == nil {

return

}

//選擇這個(gè)節(jié)點(diǎn)

pb = append(pb, root.Val)

//截止條件

if root.Left == nil && root.Right == nil && root.Val == target {

res = append(res, append([]int{}, pb...))

return

}

recurPath(target-root.Val, root.Left, pb)

recurPath(target-root.Val, root.Right, pb)

pb=pb[:len(pb)-1]

}

二叉樹基礎(chǔ)題難倒大廠程序員,我的粉絲都會(huì)寫吧的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
卫辉市| 腾冲县| 图木舒克市| 仙居县| 韶关市| 临武县| 当涂县| 高尔夫| 毕节市| 商水县| 克山县| 镇原县| 衡阳市| 新绛县| 腾冲县| 马公市| 珠海市| 成安县| 赫章县| 临武县| 芒康县| 嵊泗县| 边坝县| 香河县| 罗定市| 台安县| 盐亭县| 西城区| 定陶县| 类乌齐县| 桐乡市| 彭州市| 嘉义县| 旌德县| 乡城县| 巨鹿县| 阜南县| 湘潭县| 开化县| 尚义县| 姜堰市|