My accepted C solution 0ms (beats 100%)


  • 0
    P

    '''
    struct ListNode* swapPairs(struct ListNode* head) {

    struct ListNode *cP, *nP,*h1,*temp=head; 
    
    if(head==NULL || head->next==NULL)
    return head;
    
    h1 = head->next;
    cP = head;
    //nP = cP->next;
    
    while(cP!=NULL && cP->next!= NULL)
    {
        nP = cP->next;
        temp->next = nP;
        
        temp = cP;
        cP->next = nP->next;
        nP->next = cP;
        
        
        cP = cP->next;
        
    }
    return h1;
    

    }

    '''


Log in to reply
 

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