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)/最长同值路径 [longest-univalue-path].html
2022-03-29 12:43:11 +08:00

34 lines
1.0 KiB
HTML

<p>给定一个二叉树的<meta charset="UTF-8" />&nbsp;<code>root</code>&nbsp;,返回&nbsp;<em>最长的路径的长度</em> ,这个路径中的&nbsp;<em>每个节点具有相同值</em>&nbsp;。 这条路径可以经过也可以不经过根节点。</p>
<p><strong>两个节点之间的路径长度</strong>&nbsp;由它们之间的边数表示。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/10/13/ex1.jpg" /></p>
<pre>
<strong>输入:</strong>root = [5,4,5,1,1,5]
<strong>输出:</strong>2
</pre>
<p><strong>示例 2:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/10/13/ex2.jpg" /></p>
<pre>
<strong>输入:</strong>root = [1,4,5,4,4,5]
<strong>输出:</strong>2
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>树的节点数的范围是<meta charset="UTF-8" />&nbsp;<code>[0, 10<sup>4</sup>]</code>&nbsp;</li>
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
<li>树的深度将不超过 <code>1000</code>&nbsp;</li>
</ul>