We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
When we reach the part of the code that says "Attach the remaining elements", we have already attached all the elements from 1 list, and only some (if any) of the elements from the other list. For whichever original list that still has elements in it, we simply attach them to the end of the list we've been making. This is done in 1 step, by having the tail element in our new list point to the head element of whichever list still has elements in it.
Merge two sorted linked lists
You are viewing a single comment's thread. Return to all comments →
When we reach the part of the code that says "Attach the remaining elements", we have already attached all the elements from 1 list, and only some (if any) of the elements from the other list. For whichever original list that still has elements in it, we simply attach them to the end of the list we've been making. This is done in 1 step, by having the tail element in our new list point to the head element of whichever list still has elements in it.
HackerRank solutions.