You are viewing a single comment's thread. Return to all comments →
Here is another solution with recursive {
if (!head1 && !head2) return nullptr; else if (!head1 || !head2) return head2 ? head2 : head1; SinglyLinkedListNode* merged; SinglyLinkedListNode* temp; if (head1->data <= head2->data) { merged = head1; temp = head2; } else { merged = head2; temp = head1; } merged->next = mergeLists(merged->next, temp); return merged;
}
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Merge two sorted linked lists
You are viewing a single comment's thread. Return to all comments →
Here is another solution with recursive {
}