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)/二叉树的完全性检验 [check-completeness-of-a-binary-tree].html
2022-03-29 12:43:11 +08:00

35 lines
1.6 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>给定一个二叉树的<meta charset="UTF-8" />&nbsp;<code>root</code>&nbsp;,确定它是否是一个&nbsp;<em>完全二叉树</em>&nbsp;</p>
<p>在一个&nbsp;<strong><a href="https://baike.baidu.com/item/完全二叉树/7773232?fr=aladdin" target="_blank">完全二叉树</a></strong>&nbsp;中,除了最后一个关卡外,所有关卡都是完全被填满的,并且最后一个关卡中的所有节点都是尽可能靠左的。它可以包含<meta charset="UTF-8" />&nbsp;<code>1</code>&nbsp;<meta charset="UTF-8" />&nbsp;<code>2<sup>h</sup></code>&nbsp;节点之间的最后一级 <code>h</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/15/complete-binary-tree-1.png" /></p>
<pre>
<strong>输入:</strong>root = [1,2,3,4,5,6]
<strong>输出:</strong>true
<strong>解释:</strong>最后一层前的每一层都是满的(即,结点值为 {1} 和 {2,3} 的两层),且最后一层中的所有结点({4,5,6})都尽可能地向左。
</pre>
<p><strong>示例 2</strong></p>
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/15/complete-binary-tree-2.png" /></strong></p>
<pre>
<strong>输入:</strong>root = [1,2,3,4,5,null,7]
<strong>输出:</strong>false
<strong>解释:</strong>值为 7 的结点没有尽可能靠向左侧。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>树的结点数在范围 <meta charset="UTF-8" />&nbsp;<code>[1, 100]</code>&nbsp;内。</li>
<li><code>1 &lt;= Node.val &lt;= 1000</code></li>
</ul>