5line c++ solution


  • 0
    B
        ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
            ListNode *root(nullptr), *cur(nullptr);
            while (l1 or l2) {
                ListNode **now = (l1 and (!l2 or l1->val < l2->val)) ? &l1 : &l2;
                cur = (!root ? root : cur->next) = *now;
                *now = (*now)->next;
            }
            return root;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.