938. Range Sum of BST
DFS TREE
Last updated
Was this helpful?
DFS TREE
Last updated
Was this helpful?
Given the root
node 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]
.
Example 1:
Example 2:
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.
分析
判断根在不在范围内,在的话返回root+left+right, 否则按照范围返回左或者右