# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None
classSolution(object): defrangeSumBST(self, root, L, R): """ :type root: TreeNode :type L: int :type R: int :rtype: int """ if root == None: return0 sum = 0 if L <= root.val and root.val <= R: sum += root.val if root.val > L: sum += self.rangeSumBST(root.left, L, R) if root.val < R: sum += self.rangeSumBST(root.right, L, R) return sum