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 Normal View History

2023-12-09 18:42:21 +08:00
<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>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<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>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p>找出并返回能够形成的 <strong>最长数对链的长度</strong></p>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p>你不需要用到所有的数对,你可以以任何顺序选择其中的一些数对来构造。</p>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
2022-03-27 20:46:41 +08:00
<pre>
2023-12-09 18:42:21 +08:00
<strong>输入:</strong>pairs =&nbsp;[[1,2], [2,3], [3,4]]
2022-03-27 20:46:41 +08:00
<strong>输出:</strong>2
2023-12-09 18:42:21 +08:00
<strong>解释:</strong>最长的数对链是 [1,2] -&gt; [3,4] 。
2022-03-27 20:46:41 +08:00
</pre>
2023-12-09 18:42:21 +08:00
<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>
2022-03-27 20:46:41 +08:00
<p><strong>提示:</strong></p>
<ul>
2023-12-09 18:42:21 +08:00
<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>
2022-03-27 20:46:41 +08:00
</ul>