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)/不相交的线 [uncrossed-lines].html
2022-03-29 12:43:11 +08:00

52 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>在两条独立的水平线上按给定的顺序写下 <code>nums1</code><code>nums2</code> 中的整数。</p>
<p>现在,可以绘制一些连接两个数字 <code>nums1[i]</code>&nbsp;<code>nums2[j]</code>&nbsp;的直线,这些直线需要同时满足满足:</p>
<ul>
<li>&nbsp;<code>nums1[i] == nums2[j]</code></li>
<li>且绘制的直线不与任何其他连线(非水平线)相交。</li>
</ul>
<p>请注意,连线即使在端点也不能相交:每个数字只能属于一条连线。</p>
<p>以这种方法绘制线条,并返回可以绘制的最大连线数。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2019/04/26/142.png" style="width: 400px; height: 286px;" />
<pre>
<strong>输入:</strong>nums1 = <span id="example-input-1-1">[1,4,2]</span>, nums2 = <span id="example-input-1-2">[1,2,4]</span>
<strong>输出:</strong><span id="example-output-1">2</span>
<strong>解释:</strong>可以画出两条不交叉的线,如上图所示。
但无法画出第三条不相交的直线,因为从 nums1[1]=4 到 nums2[2]=4 的直线将与从 nums1[2]=2 到 nums2[1]=2 的直线相交。
</pre>
<div>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums1 = <span id="example-input-2-1">[2,5,1,2,5]</span>, nums2 = <span id="example-input-2-2">[10,5,2,1,5,2]</span>
<strong>输出:</strong><span id="example-output-2">3</span>
</pre>
<div>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>nums1 = <span id="example-input-3-1">[1,3,7,1,7,5]</span>, nums2 = <span id="example-input-3-2">[1,9,2,5,1]</span>
<strong>输出:</strong><span id="example-output-3">2</span></pre>
<p>&nbsp;</p>
</div>
</div>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums1.length, nums2.length &lt;= 500</code></li>
<li><code>1 &lt;= nums1[i], nums2[j] &lt;= 2000</code></li>
</ul>
<p>&nbsp;</p>