|
| 1 | +<h2><a href="https://leetcode.com/problems/merge-in-between-linked-lists">1765. Merge In Between Linked Lists</a></h2><h3>Medium</h3><hr><p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p> |
| 2 | + |
| 3 | +<p>Remove <code>list1</code>'s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p> |
| 4 | + |
| 5 | +<p>The blue edges and nodes in the following figure indicate the result:</p> |
| 6 | +<img alt="" src="https://assets.leetcode.com/uploads/2020/11/05/fig1.png" style="height: 130px; width: 504px;" /> |
| 7 | +<p><em>Build the result list and return its head.</em></p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | +<img alt="" src="https://assets.leetcode.com/uploads/2024/03/01/ll.png" style="width: 609px; height: 210px;" /> |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> list1 = [10,1,13,6,9,5], a = 3, b = 4, list2 = [1000000,1000001,1000002] |
| 14 | +<strong>Output:</strong> [10,1,13,1000000,1000001,1000002,5] |
| 15 | +<strong>Explanation:</strong> 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. |
| 16 | +</pre> |
| 17 | + |
| 18 | +<p><strong class="example">Example 2:</strong></p> |
| 19 | +<img alt="" src="https://assets.leetcode.com/uploads/2020/11/05/merge_linked_list_ex2.png" style="width: 463px; height: 140px;" /> |
| 20 | +<pre> |
| 21 | +<strong>Input:</strong> list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004] |
| 22 | +<strong>Output:</strong> [0,1,1000000,1000001,1000002,1000003,1000004,6] |
| 23 | +<strong>Explanation:</strong> The blue edges and nodes in the above figure indicate the result. |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p> </p> |
| 27 | +<p><strong>Constraints:</strong></p> |
| 28 | + |
| 29 | +<ul> |
| 30 | + <li><code>3 <= list1.length <= 10<sup>4</sup></code></li> |
| 31 | + <li><code>1 <= a <= b < list1.length - 1</code></li> |
| 32 | + <li><code>1 <= list2.length <= 10<sup>4</sup></code></li> |
| 33 | +</ul> |
0 commit comments