← 返回 meta 的题目列表Sum of BST Nodes Within Given Range
类型:online_judge
meta
Given the root of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].
Input:
root: The root node of the binary search tree
low: An integer
high: An integer
Output:
The sum of all node values within the range [low, high]
Example:
Input: root = [10,5,15,3,7,null,18], low = 7, high = 15
Output: 32
Constraints:
The number of nodes in the tree is in the range [1, 2 * 10^4]
1 <= Node.val <= 10^5
1 <= low <= high <= 10^5
All Node.val are unique
Example
Input
root = [10,5,15,3,7,null,18], low = 7, high = 15