cpp beats 96%,  better than O(n) traversal.
\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode(int x) : v
```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n    int rangeSumBST(TreeNode* root, int L, int R) {\n      \n      if(!root) return 0;\n      \n      if(root->val >= L && root->val <= R){\n        return root->val + rangeSumBST(root->left,L,R) + rangeSumBST(root->right,L,R);\n      }else if(root->val < L){\n        return rangeSumBST(root->right,L,R);\n      }else {\n        return rangeSumBST(root->left,L,R);\n      }\n    }\n  \n  \n};\n```
[]