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)/二叉树中的链表 [linked-list-in-binary-tree].html

42 lines
1.9 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>给你一棵以&nbsp;<code>root</code>&nbsp;为根的二叉树和一个&nbsp;<code>head</code>&nbsp;为第一个节点的链表。</p>
<p>如果在二叉树中,存在一条一直向下的路径,且每个点的数值恰好一一对应以&nbsp;<code>head</code>&nbsp;为首的链表中每个节点的值,那么请你返回 <code>True</code> ,否则返回 <code>False</code></p>
<p>一直向下的路径的意思是:从树中某个节点开始,一直连续向下的路径。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/02/29/sample_1_1720.png" style="height: 280px; width: 220px;"></strong></p>
<pre><strong>输入:</strong>head = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]
<strong>输出:</strong>true
<strong>解释:</strong>树中蓝色的节点构成了与链表对应的子路径。
</pre>
<p><strong>示例 2</strong></p>
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/02/29/sample_2_1720.png" style="height: 280px; width: 220px;"></strong></p>
<pre><strong>输入:</strong>head = [1,4,2,6], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]
<strong>输出:</strong>true
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>head = [1,4,2,6,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]
<strong>输出:</strong>false
<strong>解释:</strong>二叉树中不存在一一对应链表的路径。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>二叉树和链表中的每个节点的值都满足&nbsp;<code>1 &lt;= node.val&nbsp;&lt;= 100</code>&nbsp;</li>
<li>链表包含的节点数目在&nbsp;<code>1</code>&nbsp;&nbsp;<code>100</code>&nbsp;之间。</li>
<li>二叉树包含的节点数目在&nbsp;<code>1</code>&nbsp;&nbsp;<code>2500</code>&nbsp;之间。</li>
</ul>