range sum of bst

🏠
 1 # Definition for a binary tree node.
 2 # class TreeNode:
 3 #     def __init__(self, val=0, left=None, right=None):
 4 #         self.val = val
 5 #         self.left = left
 6 #         self.right = right
 7 class Solution:
 8     def rangeSumBST(self, root: TreeNode, L: int, R: int) -> int:
 9         def rec(node):
10             if node.left:
11                 rec(node.left)
12             if node.right:
13                 rec(node.right)
14             total[0] += node.val if L <= node.val <= R else 0
15         total = [0]
16         rec(root)
17         return total[0]