mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
36 lines
1.3 KiB
HTML
36 lines
1.3 KiB
HTML
|
<p>给你一个二叉树的根节点 <code>root</code>。设根节点位于二叉树的第 <code>1</code> 层,而根节点的子节点位于第 <code>2</code> 层,依此类推。</p>
|
|||
|
|
|||
|
<p>请返回层内元素之和 <strong>最大</strong> 的那几层(可能只有一层)的层号,并返回其中 <strong>最小</strong> 的那个。</p>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>示例 1:</strong></p>
|
|||
|
|
|||
|
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/08/17/capture.jpeg" style="height: 175px; width: 200px;" /></strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>root = [1,7,0,7,-8,null,null]
|
|||
|
<strong>输出:</strong>2
|
|||
|
<strong>解释:</strong>
|
|||
|
第 1 层各元素之和为 1,
|
|||
|
第 2 层各元素之和为 7 + 0 = 7,
|
|||
|
第 3 层各元素之和为 7 + -8 = -1,
|
|||
|
所以我们返回第 2 层的层号,它的层内元素之和最大。
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>示例 2:</strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>root = [989,null,10250,98693,-89388,null,null,null,-32127]
|
|||
|
<strong>输出:</strong>2
|
|||
|
</pre>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>提示:</strong></p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li>树中的节点数在<meta charset="UTF-8" /> <code>[1, 10<sup>4</sup>]</code>范围内<meta charset="UTF-8" /></li>
|
|||
|
<li><code>-10<sup>5</sup> <= Node.val <= 10<sup>5</sup></code></li>
|
|||
|
</ul>
|