1669. Merge In Between Linked Lists Medium
1/**
2 * [1669] Merge In Between Linked Lists
3 *
4 * You are given two linked lists: list1 and list2 of sizes n and m respectively.
5 * Remove list1's nodes from the a^th node to the b^th node, and put list2 in their place.
6 * The blue edges and nodes in the following figure indicate the result:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/05/fig1.png" style="height: 130px; width: 504px;" />
8 * Build the result list and return its head.
9 *
10 * Example 1:
11 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/05/merge_linked_list_ex1.png" style="width: 406px; height: 140px;" />
12 * Input: list1 = [0,1,2,3,4,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]
13 * Output: [0,1,2,1000000,1000001,1000002,5]
14 * Explanation: We remove the nodes 3 and 4 and put the entire list2 in their place. The blue edges and nodes in the above figure indicate the result.
15 *
16 * Example 2:
17 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/05/merge_linked_list_ex2.png" style="width: 463px; height: 140px;" />
18 * Input: list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]
19 * Output: [0,1,1000000,1000001,1000002,1000003,1000004,6]
20 * Explanation: The blue edges and nodes in the above figure indicate the result.
21 *
22 *
23 * Constraints:
24 *
25 * 3 <= list1.length <= 10^4
26 * 1 <= a <= b < list1.length - 1
27 * 1 <= list2.length <= 10^4
28 *
29 */
30pub struct Solution {}
31use crate::util::linked_list::{ListNode, to_list};
32
33// problem: https://leetcode.com/problems/merge-in-between-linked-lists/
34// discuss: https://leetcode.com/problems/merge-in-between-linked-lists/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38// Definition for singly-linked list.
39// #[derive(PartialEq, Eq, Clone, Debug)]
40// pub struct ListNode {
41// pub val: i32,
42// pub next: Option<Box<ListNode>>
43// }
44//
45// impl ListNode {
46// #[inline]
47// fn new(val: i32) -> Self {
48// ListNode {
49// next: None,
50// val
51// }
52// }
53// }
54impl Solution {
55 pub fn merge_in_between(list1: Option<Box<ListNode>>, a: i32, b: i32, list2: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
56 Some(Box::new(ListNode::new(0)))
57 }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn test_1669() {
68 }
69}
70
Back
© 2025 bowen.ge All Rights Reserved.