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)/最大层内元素和 [maximum-level-sum-of-a-binary-tree].html
2022-03-29 12:43:11 +08:00

36 lines
1.3 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>给你一个二叉树的根节点&nbsp;<code>root</code>。设根节点位于二叉树的第 <code>1</code> 层,而根节点的子节点位于第 <code>2</code> 层,依此类推。</p>
<p>请返回层内元素之和 <strong>最大</strong> 的那几层(可能只有一层)的层号,并返回其中&nbsp;<strong>最小</strong> 的那个。</p>
<p>&nbsp;</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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>树中的节点数在<meta charset="UTF-8" />&nbsp;<code>[1, 10<sup>4</sup>]</code>范围内<meta charset="UTF-8" /></li>
<li><code>-10<sup>5</sup>&nbsp;&lt;= Node.val &lt;= 10<sup>5</sup></code></li>
</ul>