c sulution


  • 0
    L
    struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) {
        struct ListNode head;
        struct ListNode *ptr=&head;
        head.val=0;
            while(l1&&l2){
                if(l1->val>l2->val){
                    ptr->next=l2;
                    l2=l2->next;
                }
                else{
                     ptr->next=l1;
                     l1=l1->next;
                }
                ptr=ptr->next;
            }
            ptr->next=l1?l1:l2;
            return head.next;
    }
    

Log in to reply
 

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