1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/二叉搜索树中的众数 [find-mode-in-binary-search-tree].html
2022-03-29 12:43:11 +08:00

41 lines
1.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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>给你一个含重复值的二叉搜索树BST的根节点 <code>root</code> ,找出并返回 BST 中的所有 <a href="https://baike.baidu.com/item/%E4%BC%97%E6%95%B0/44796" target="_blank">众数</a>(即,出现频率最高的元素)。</p>
<p>如果树中有不止一个众数,可以按 <strong>任意顺序</strong> 返回。</p>
<p>假定 BST 满足如下定义:</p>
<ul>
<li>结点左子树中所含节点的值 <strong>小于等于</strong> 当前节点的值</li>
<li>结点右子树中所含节点的值 <strong>大于等于</strong> 当前节点的值</li>
<li>左子树和右子树都是二叉搜索树</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/11/mode-tree.jpg" style="width: 142px; height: 222px;" />
<pre>
<strong>输入:</strong>root = [1,null,2,2]
<strong>输出:</strong>[2]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>root = [0]
<strong>输出:</strong>[0]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>树中节点的数目在范围 <code>[1, 10<sup>4</sup>]</code></li>
<li><code>-10<sup>5</sup> &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
</ul>
<p>&nbsp;</p>
<p><strong>进阶:</strong>你可以不使用额外的空间吗?(假设由递归产生的隐式调用栈的开销不被计算在内)</p>