Package g1001_1100.s1035_uncrossed_lines
Class Solution
java.lang.Object
g1001_1100.s1035_uncrossed_lines.Solution
1035 - Uncrossed Lines.<p>Medium</p>
<p>You are given two integer arrays <code>nums1</code> and <code>nums2</code>. We write the integers of <code>nums1</code> and <code>nums2</code> (in the order they are given) on two separate horizontal lines.</p>
<p>We may draw connecting lines: a straight line connecting two numbers <code>nums1[i]</code> and <code>nums2[j]</code> such that:</p>
<ul>
<li><code>nums1[i] == nums2[j]</code>, and</li>
<li>the line we draw does not intersect any other connecting (non-horizontal) line.</li>
</ul>
<p>Note that a connecting line cannot intersect even at the endpoints (i.e., each number can only belong to one connecting line).</p>
<p>Return <em>the maximum number of connecting lines we can draw in this way</em>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2019/04/26/142.png" alt="" /></p>
<p><strong>Input:</strong> nums1 = [1,4,2], nums2 = [1,2,4]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> We can draw 2 uncrossed lines as in the diagram. We cannot draw 3 uncrossed lines, because the line from nums1[1] = 4 to nums2[2] = 4 will intersect the line from nums1[2]=2 to nums2[1]=2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums1 = [2,5,1,2,5], nums2 = [10,5,2,1,5,2]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums1 = [1,3,7,1,7,5], nums2 = [1,9,2,5,1]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums1.length, nums2.length <= 500</code></li>
<li><code>1 <= nums1[i], nums2[j] <= 2000</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxUncrossedLines
public int maxUncrossedLines(int[] nums1, int[] nums2)
-