/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public int rangeSumBST(TreeNode root, int low, int high) {
return f(root,low,high,0);
}
public int f(TreeNode root, int low, int high,int result){
if(root!=null){
result=f(root.left,low,high,result);
if(root.val>=low&&root.val<=high){
result+=root.val;
}
result=f(root.right,low,high,result);
}
return result;
}
}