A simple question?


  • 0
    H

    class Solution {
    public:
    ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
    if(!l1) return l2;
    if(!l2) return l1;
    ListNode *head,*temp=head;
    while(l1&&l2){
    if(l1->val<=l2->val) {head->next=l1; l1=l1->next;}
    else {head->next=l2;l2=l2->next;}
    head=head->next;
    }
    head->next= (l1) ?l1 :l2;
    return temp=temp->next;
    }
    };

    the Listnode pointer(head) don't initialize, may be it is pretty dangerous?


Log in to reply
 

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