You are viewing a single comment's thread. Return to all comments →
Simpler:
if(!headA){return headB;} if(!headB){return headA;} if(headA->data < headB->data){ headA->next = MergeLists(headA->next,headB); return headA; } else{ headB->next = MergeLists(headA,headB->next); return headB; }
Simpler
Node* MergeLists(Node *a, Node*b) { if( !a) return b; if( !b) return a; if (a->data < b->data) { a->next = MergeLists(a->next, b); return a; } else { return MergeLists(b, a); } }
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 →
Simpler:
Simpler