1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/二叉搜索树的范围和 [range-sum-of-bst].html
2022-03-29 12:43:11 +08:00

29 lines
1.0 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定二叉搜索树的根结点 <code>root</code>,返回值位于范围 <em><code>[low, high]</code></em> 之间的所有结点的值的和。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/05/bst1.jpg" style="width: 400px; height: 222px;" />
<pre>
<strong>输入:</strong>root = [10,5,15,3,7,null,18], low = 7, high = 15
<strong>输出:</strong>32
</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/05/bst2.jpg" style="width: 400px; height: 335px;" />
<pre>
<strong>输入:</strong>root = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10
<strong>输出:</strong>23
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li>树中节点数目在范围 <code>[1, 2 * 10<sup>4</sup>]</code></li>
<li><code>1 <= Node.val <= 10<sup>5</sup></code></li>
<li><code>1 <= low <= high <= 10<sup>5</sup></code></li>
<li>所有 <code>Node.val</code> <strong>互不相同</strong></li>
</ul>