算法1
(递归) $O(n)$
最简洁
C++ 代码
class Solution {
public:
int rangeSumBST(TreeNode* root, int low, int high) {
if(root == nullptr) return 0;
return rangeSumBST(root->left, low, high)
+ rangeSumBST(root->right, low, high)
+ (root-> val >= low && root->val <= high ? root->val : 0);
}
};