Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int rangeSumBST(TreeNode* root, int L, int R) {
- int sum = 0;
- if(!root){
- return sum;
- }
- if(L <= root->val && R >= root->val){
- sum += root->val;
- }
- if(L < root->val){
- sum += rangeSumBST(root->left,L,R);
- }
- if(R > root->val){
- sum += rangeSumBST(root->right,L,R);
- }
- return sum;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement