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)/最长数对链 [maximum-length-of-pair-chain].html

35 lines
1.4 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>n</code>&nbsp;个数对组成的数对数组&nbsp;<code>pairs</code>&nbsp;,其中&nbsp;<code>pairs[i] = [left<sub>i</sub>, right<sub>i</sub>]</code>&nbsp;&nbsp;<code>left<sub>i</sub>&nbsp;&lt; right<sub>i</sub></code><sub></sub></p>
<p>现在,我们定义一种 <strong>跟随</strong> 关系,当且仅当&nbsp;<code>b &lt; c</code>&nbsp;时,数对&nbsp;<code>p2 = [c, d]</code>&nbsp;才可以跟在&nbsp;<code>p1 = [a, b]</code>&nbsp;后面。我们用这种形式来构造 <strong>数对链</strong></p>
<p>找出并返回能够形成的 <strong>最长数对链的长度</strong></p>
<p>你不需要用到所有的数对,你可以以任何顺序选择其中的一些数对来构造。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>pairs =&nbsp;[[1,2], [2,3], [3,4]]
<strong>输出:</strong>2
<strong>解释:</strong>最长的数对链是 [1,2] -&gt; [3,4] 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>pairs = [[1,2],[7,8],[4,5]]
<b>输出:</b>3
<b>解释:</b>最长的数对链是 [1,2] -&gt; [4,5] -&gt; [7,8] 。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == pairs.length</code></li>
<li><code>1 &lt;= n &lt;= 1000</code></li>
<li><code>-1000 &lt;= left<sub>i</sub>&nbsp;&lt; right<sub>i</sub>&nbsp;&lt;= 1000</code></li>
</ul>