short c++

  • 0
        ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
            ListNode root(-1), *cur(&root);
            while(l1 or l2) {
                ListNode** l=&l1;
                if(!l1 or l2 and l2->val < l1->val) l=&l2;
                cur = cur->next = *l;
                *l = (*l)->next;

    not quite as short as the recursive solutions.

Log in to reply

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