1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-12 02:41:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

存量题库数据更新

This commit is contained in:
2023-12-09 18:42:21 +08:00
parent a788808cd7
commit c198538f10
10843 changed files with 288489 additions and 248355 deletions

View File

@@ -1,19 +1,31 @@
<p>定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过也可能不穿过根结点</p>
<p>你一棵二叉树的根节点,返回该树的 <strong>直径</strong> </p>
<p>二叉树的 <strong>直径</strong> 是指树中任意两个节点之间最长路径的 <strong>长度</strong> 。这条路径可能经过也可能不经过根节点 <code>root</code></p>
<p>两节点之间路径的 <strong>长度</strong> 由它们之间边数表示。</p>
<p>&nbsp;</p>
<p><strong>示例 :</strong><br>
给定二叉树</p>
<pre> 1
/ \
2 3
/ \
4 5
<p><strong class="example">示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/06/diamtree.jpg" style="width: 292px; height: 302px;" />
<pre>
<strong>输入:</strong>root = [1,2,3,4,5]
<strong>输出:</strong>3
<strong>解释:</strong>3 ,取路径 [4,2,1,3] 或 [5,2,1,3] 的长度。
</pre>
<p>返回&nbsp;<strong>3</strong>, 它的长度是路径 [4,2,1,3] 或者&nbsp;[5,2,1,3]。</p>
<p><strong class="example">示例 2</strong></p>
<pre>
<strong>输入:</strong>root = [1,2]
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p><strong>注意</strong>两结点之间的路径长度是以它们之间边的数目表示。</p>
<p><strong>提示</strong></p>
<ul>
<li>树中节点数目在范围 <code>[1, 10<sup>4</sup>]</code></li>
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
</ul>