mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-02-14 13:54:36 +00:00
17 lines
374 B
C
17 lines
374 B
C
int rangeSumBST(struct TreeNode *root, int L, int R)
|
|
{
|
|
if (root == NULL)
|
|
{
|
|
return 0;
|
|
}
|
|
else if (root->val >= L && root->val <= R)
|
|
{
|
|
return root->val + rangeSumBST(root->left, L, R) +
|
|
rangeSumBST(root->right, L, R);
|
|
}
|
|
else
|
|
{
|
|
return rangeSumBST(root->left, L, R) + rangeSumBST(root->right, L, R);
|
|
}
|
|
}
|