mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<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> </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> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li>树中节点的数目在范围 <code>[1, 10<sup>4</sup>]</code> 内</li>
 | 
						||
	<li><code>-10<sup>5</sup> <= Node.val <= 10<sup>5</sup></code></li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>进阶:</strong>你可以不使用额外的空间吗?(假设由递归产生的隐式调用栈的开销不被计算在内)</p>
 |