mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-11 10:21:43 +08:00
存量题库数据更新
This commit is contained in:
@@ -1,66 +1,46 @@
|
||||
<p>给定一个二叉树,编写一个函数来获取这个树的最大宽度。树的宽度是所有层中的最大宽度。这个二叉树与<strong>满二叉树(full binary tree)</strong>结构相同,但一些节点为空。</p>
|
||||
<p>给你一棵二叉树的根节点 <code>root</code> ,返回树的 <strong>最大宽度</strong> 。</p>
|
||||
|
||||
<p>每一层的宽度被定义为两个端点(该层最左和最右的非空节点,两端点间的<code>null</code>节点也计入长度)之间的长度。</p>
|
||||
<p>树的 <strong>最大宽度</strong> 是所有层中最大的 <strong>宽度</strong> 。</p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<div class="original__bRMd">
|
||||
<div>
|
||||
<p>每一层的 <strong>宽度</strong> 被定义为该层最左和最右的非空节点(即,两个端点)之间的长度。将这个二叉树视作与满二叉树结构相同,两端点间会出现一些延伸到这一层的 <code>null</code> 节点,这些 <code>null</code> 节点也计入长度。</p>
|
||||
|
||||
<p>题目数据保证答案将会在 <strong>32 位</strong> 带符号整数范围内。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/05/03/width1-tree.jpg" style="width: 359px; height: 302px;" />
|
||||
<pre>
|
||||
<strong>输入:</strong>
|
||||
|
||||
1
|
||||
/ \
|
||||
3 2
|
||||
/ \ \
|
||||
5 3 9
|
||||
|
||||
<strong>输出:</strong> 4
|
||||
<strong>解释:</strong> 最大值出现在树的第 3 层,宽度为 4 (5,3,null,9)。
|
||||
<strong>输入:</strong>root = [1,3,2,5,3,null,9]
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>最大宽度出现在树的第 3 层,宽度为 4 (5,3,null,9) 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/14/maximum-width-of-binary-tree-v3.jpg" style="width: 442px; height: 422px;" />
|
||||
<pre>
|
||||
<strong>输入:</strong>
|
||||
|
||||
1
|
||||
/
|
||||
3
|
||||
/ \
|
||||
5 3
|
||||
|
||||
<strong>输出:</strong> 2
|
||||
<strong>解释:</strong> 最大值出现在树的第 3 层,宽度为 2 (5,3)。
|
||||
<strong>输入:</strong>root = [1,3,2,5,null,null,9,6,null,7]
|
||||
<strong>输出:</strong>7
|
||||
<strong>解释:</strong>最大宽度出现在树的第 4 层,宽度为 7 (6,null,null,null,null,null,7) 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/05/03/width3-tree.jpg" style="width: 289px; height: 299px;" />
|
||||
<pre>
|
||||
<strong>输入:</strong>
|
||||
|
||||
1
|
||||
/ \
|
||||
3 2
|
||||
/
|
||||
5
|
||||
|
||||
<strong>输出:</strong> 2
|
||||
<strong>解释:</strong> 最大值出现在树的第 2 层,宽度为 2 (3,2)。
|
||||
<strong>输入:</strong>root = [1,3,2,5]
|
||||
<strong>输出:</strong>2
|
||||
<strong>解释:</strong>最大宽度出现在树的第 2 层,宽度为 2 (3,2) 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 4:</strong></p>
|
||||
<p> </p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
1
|
||||
/ \
|
||||
3 2
|
||||
/ \
|
||||
5 9
|
||||
/ \
|
||||
6 7
|
||||
<strong>输出:</strong> 8
|
||||
<strong>解释:</strong> 最大值出现在树的第 4 层,宽度为 8 (6,null,null,null,null,null,null,7)。
|
||||
</pre>
|
||||
|
||||
<p><strong>注意:</strong> 答案在32位有符号整数的表示范围内。</p>
|
||||
<ul>
|
||||
<li>树中节点的数目范围是 <code>[1, 3000]</code></li>
|
||||
<li><code>-100 <= Node.val <= 100</code></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user