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)/二叉树的层平均值 [average-of-levels-in-binary-tree].html

35 lines
1.1 KiB
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
<p>给定一个非空二叉树的根节点<meta charset="UTF-8" />&nbsp;<code>root</code>&nbsp;, 以数组的形式返回每一层节点的平均值。与实际答案相差&nbsp;<code>10<sup>-5</sup></code> 以内的答案可以被接受。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/03/09/avg1-tree.jpg" /></p>
<pre>
<strong>输入:</strong>root = [3,9,20,null,null,15,7]
<strong>输出:</strong>[3.00000,14.50000,11.00000]
<strong>解释:</strong>第 0 层的平均值为 3,第 1 层的平均值为 14.5,第 2 层的平均值为 11 。
因此返回 [3, 14.5, 11] 。
</pre>
<p><strong>示例 2:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/03/09/avg2-tree.jpg" /></p>
<pre>
<strong>输入:</strong>root = [3,9,20,15,7]
<strong>输出:</strong>[3.00000,14.50000,11.00000]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<p><meta charset="UTF-8" /></p>
<ul>
<li>树中节点数量在&nbsp;<code>[1, 10<sup>4</sup>]</code> 范围内</li>
<li><code>-2<sup>31</sup>&nbsp;&lt;= Node.val &lt;= 2<sup>31</sup>&nbsp;- 1</code></li>
</ul>