Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int rangeSumBST(TreeNode* root, int L, int R) {
  4. int sum = 0;
  5. if(!root){
  6. return sum;
  7. }
  8. if(L <= root->val && R >= root->val){
  9. sum += root->val;
  10. }
  11. if(L < root->val){
  12. sum += rangeSumBST(root->left,L,R);
  13. }
  14. if(R > root->val){
  15. sum += rangeSumBST(root->right,L,R);
  16. }
  17. return sum;
  18. }
  19. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement