Description
Given two integer arrays, draw connecting lines between equal elements. Return maximum lines you can draw without any lines crossing.
Examples
Input:
nums1 = [1,4,2], nums2 = [1,2,4]Output:
2Explanation:
Connect 1-1 and 4-4.
Input:
nums1 = [3,1,2,1,5], nums2 = [2,3,1,5]Output:
3Explanation:
Connect 3-3, 1-1, and 5-5 without any lines crossing. The connection 2-2 would cross with other connections, so skipping it to maximize uncrossed lines.
Input:
nums1 = [1], nums2 = [1,2,3,1]Output:
1Explanation:
With only one element in nums1, it is possible to connect at most one line. Connecting the single element 1 from nums1 to any of the matching 1's in nums2.
Constraints
- •
1 ≤ nums1.length, nums2.length ≤ 500