/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int rangeSumBST(TreeNode* root, int L, int R) {
if (NULL == root)
return 0;
int32_t sum = 0;
if (root->val >= L && root->val <= R)
{
sum += root->val;
}
return sum + (rangeSumBST(root->left, L, R)) + (rangeSumBST(root->right, L, R));
}
};
leetcode 二叉搜索树的范围和
最新推荐文章于 2024-08-14 11:22:43 发布