The list is broken,why

  • 0

    struct ListNode* swapPairs(struct ListNode* head)
    struct ListNode* parthead;
    struct ListNode* p1;
    struct ListNode* p2;
    if(head == NULL||head->next ==NULL)
    return head;
    parthead = head;
    head = head->next;
    while(parthead != NULL&&parthead->next !=NULL)
    p1 = parthead;
    p2 = parthead->next->next;
    parthead = parthead->next;
    parthead->next = p1;
    parthead->next->next = p2;
    parthead = parthead->next->next;
    return head;

Log in to reply

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