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)/链表组件 [linked-list-components].html
2022-03-29 12:43:11 +08:00

38 lines
1.7 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>head</code>,该链表上的每个结点都有一个 <strong>唯一的整型值</strong> 。同时给定列表&nbsp;<code>nums</code>,该列表是上述链表中整型值的一个子集。</p>
<p>返回列表&nbsp;<code>nums</code>&nbsp;中组件的个数,这里对组件的定义为:链表中一段最长连续结点的值(该值必须在列表&nbsp;<code>nums</code>&nbsp;中)构成的集合。</p>
<p>&nbsp;</p>
<p><strong>示例&nbsp;1</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/07/22/lc-linkedlistcom1.jpg" /></p>
<pre>
<strong>输入:</strong> head = [0,1,2,3], nums = [0,1,3]
<strong>输出:</strong> 2
<strong>解释:</strong> 链表中,0 和 1 是相连接的,且 nums 中不包含 2所以 [0, 1] 是 nums 的一个组件,同理 [3] 也是一个组件,故返回 2。</pre>
<p><strong>示例 2</strong></p>
<p><strong>&nbsp;</strong><img src="https://assets.leetcode.com/uploads/2021/07/22/lc-linkedlistcom2.jpg" /></p>
<pre>
<strong>输入:</strong> head = [0,1,2,3,4], nums = [0,3,1,4]
<strong>输出:</strong> 2
<strong>解释:</strong> 链表中0 和 1 是相连接的3 和 4 是相连接的,所以 [0, 1] 和 [3, 4] 是两个组件,故返回 2。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>链表中节点数为<code>n</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>
<li><code>0 &lt;= Node.val &lt; n</code></li>
<li><code>Node.val</code>&nbsp;中所有值 <strong>不同</strong></li>
<li><code>1 &lt;= nums.length &lt;= n</code></li>
<li><code>0 &lt;= nums[i] &lt; n</code></li>
<li><code>nums</code> 中所有值 <strong>不同</strong></li>
</ul>