Range Sum of BST
ID: 938; easy
Last updated
ID: 938; easy
Last updated
We utilize the condition that the tree is a BST. Note that you can use a normal traversal to traverse all the nodes, but it is not necessary to visit some nodes.
If root.val
is already less than or equal to low
(less than high
of course), we only traverse its right subtree. If root.val
is already larger than or equal to high
(more than low
), we only traverse its left subtree.