Skip to content

Commit 95262ed

Browse files
Range Sum of BST
1 parent 47bc870 commit 95262ed

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Trees/range-sum-of-bst.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int rangeSumBST(TreeNode* root, int L, int R) {
4+
if(root==NULL){
5+
return 0;
6+
}
7+
else{
8+
int sum=rangeSumBST( root->left, L, R)+rangeSumBST(root->right, L, R);
9+
if(root->val>=L && root->val<=R){
10+
sum+=root->val;
11+
}
12+
return sum;
13+
}
14+
}
15+
};

0 commit comments

Comments
 (0)