Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-05-18_16-20-35.png
48.7 KB
#medium
#N1669. Merge In Between Linked Lists
problem link
#solution
class Solution {
public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
ListNode head=list1;
int diff=b-a;
while(a-- > 1){
list1=list1.next;
}
ListNode move=list1.next;
list1.next=list2;
while(diff-- >= 0){
move=move.next;
}
while(list2.next!=null){
list2=list2.next;
}
list2.next=move;

return head;
}
}