package main
type TreeNode struct {
Valint
Left *TreeNode
Right *TreeNode
}
//938. 二叉搜索树的范围和
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
}