Skip to content

Commit 18f3716

Browse files
authored
Create 1669-merge-in-between-linked-lists.java
1 parent 1c4fa72 commit 18f3716

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Diff for: java/1669-merge-in-between-linked-lists.java

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
3+
ListNode curr = list1;
4+
int i = 0;
5+
while (i < a - 1) {
6+
curr = curr.next;
7+
i++;
8+
}
9+
10+
ListNode head = curr;
11+
while (i <= b) {
12+
curr = curr.next;
13+
i++;
14+
}
15+
head.next = list2;
16+
17+
while (list2.next != null)
18+
list2 = list2.next;
19+
list2.next = curr;
20+
return list1;
21+
}
22+
}

0 commit comments

Comments
 (0)