1035. Uncrossed Lines Medium
1/**
2 * [1035] Uncrossed Lines
3 *
4 * You are given two integer arrays nums1 and nums2. We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines.
5 * We may draw connecting lines: a straight line connecting two numbers nums1[i] and nums2[j] such that:
6 *
7 * nums1[i] == nums2[j], and
8 * the line we draw does not intersect any other connecting (non-horizontal) line.
9 *
10 * Note that a connecting line cannot intersect even at the endpoints (i.e., each number can only belong to one connecting line).
11 * Return the maximum number of connecting lines we can draw in this way.
12 *
13 * Example 1:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2019/04/26/142.png" style="width: 400px; height: 286px;" />
15 * Input: nums1 = [1,4,2], nums2 = [1,2,4]
16 * Output: 2
17 * Explanation: We can draw 2 uncrossed lines as in the diagram.
18 * 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.
19 *
20 * Example 2:
21 *
22 * Input: nums1 = [2,5,1,2,5], nums2 = [10,5,2,1,5,2]
23 * Output: 3
24 *
25 * Example 3:
26 *
27 * Input: nums1 = [1,3,7,1,7,5], nums2 = [1,9,2,5,1]
28 * Output: 2
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= nums1.length, nums2.length <= 500
34 * 1 <= nums1[i], nums2[j] <= 2000
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/uncrossed-lines/
40// discuss: https://leetcode.com/problems/uncrossed-lines/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn max_uncrossed_lines(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_1035() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.