Class Solution
-
- All Implemented Interfaces:
public final class Solution
1035 - Uncrossed Lines.
Medium
You are given two integer arrays
nums1
andnums2
. We write the integers ofnums1
andnums2
(in the order they are given) on two separate horizontal lines.We may draw connecting lines: a straight line connecting two numbers
nums1[i]
andnums2[j]
such that:nums1[i] == nums2[j]
, andthe line we draw does not intersect any other connecting (non-horizontal) line.
Note that a connecting line cannot intersect even at the endpoints (i.e., each number can only belong to one connecting line).
Return the maximum number of connecting lines we can draw in this way.
Example 1:
Input: nums1 = 1,4,2, nums2 = 1,2,4
Output: 2
Explanation: We can draw 2 uncrossed lines as in the diagram. We cannot draw 3 uncrossed lines, because the line from nums11 = 4 to nums22 = 4 will intersect the line from nums12=2 to nums21=2.
Example 2:
Input: nums1 = 2,5,1,2,5, nums2 = 10,5,2,1,5,2
Output: 3
Example 3:
Input: nums1 = 1,3,7,1,7,5, nums2 = 1,9,2,5,1
Output: 2
Constraints:
1 <= nums1.length, nums2.length <= 500
1 <= nums1[i], nums2[j] <= 2000
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final Integer
maxUncrossedLines(IntArray nums1, IntArray nums2)
-
-
Method Detail
-
maxUncrossedLines
final Integer maxUncrossedLines(IntArray nums1, IntArray nums2)
-
-
-
-