938 Range Sum of BST
Previous1379 Find a Corresponding Node of a Binary Tree in a Clone of That TreeNext222 Count Complete Tree Nodes
Last updated
Last updated
Given the root
node of a binary search tree, return the sum of values of all nodes with a value in the range [low, high]
.
Example 1:
Example 2:
Constraints:
The number of nodes in the tree is in the range [1, 2 * 104]
.
1 <= Node.val <= 105
1 <= low <= high <= 105
All Node.val
are unique.
嘛,简单题,就是套中序遍历模板。但我竟然背不出来。S:O(h),T:O(n)。其实这一题直接用递归很快就完事