package main
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func rangeSumBST(root *TreeNode, low int, high int) int {
sum := 0
if root == nil {
return sum
}
//中序遍历左中右处理即可
var searchBST func(node *TreeNode)
searchBST = func(node *TreeNode) {
if node == nil {
return
}
searchBST(node.Left)
if node.Val >= low && node.Val <= high {
sum += node.Val
}
searchBST(node.Right)
}
searchBST(root)
return sum
}