1 Star 0 Fork 0

catyMap/AlgorithmNote

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rangeSumBST.go 382 Bytes
一键复制 编辑 原始数据 按行查看 历史
catyMap 提交于 2021-04-29 08:16 +08:00 . 4/29更新 添加双指针,二分查找等题目
package main
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func rangeSumBST(root *TreeNode ,low int, high int) int {
sum := 0
var depth func(node *TreeNode)
depth = func(node *TreeNode) {
if node == nil {
return
}
if node.Val >= low && node.Val <= high {
sum += node.Val
}
depth(node.Left)
depth(node.Right)
}
depth(root)
return sum
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dogemap/algorithm-note.git
git@gitee.com:dogemap/algorithm-note.git
dogemap
algorithm-note
AlgorithmNote
dc486f96f6c1

搜索帮助