---
# System prepended metadata

title: LeetCode 練習：2022/12/07
tags: [LeetCode 938, LeetCode]

---

# LeetCode 練習：2022/12/07


## 938. Range Sum of BST
[題目938](https://leetcode.com/problems/range-sum-of-bst/description/)
```python=
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def rangeSumBST(self, root: Optional[TreeNode], low: int, high: int) -> int:    

        if root == None: return 0

        if root.val < low: return self.rangeSumBST(root.right, low, high)
        if root.val > high: return self.rangeSumBST(root.left, low, high)

        return  root.val + self.rangeSumBST(root.left, low, high) + self.rangeSumBST(root.right, low, high)
```

###### tags: `LeetCode`,`LeetCode 938`