Why my code always RE??


  • 0
    F
    ListNode*swapnode(ListNode** p,ListNode** q)
    {
    (*p)->next=(*q)->next;
    (*q)->next=(*p);
    return (ListNode*)(*q);
    }
    class Solution {
    public:
    ListNode *swapPairs(ListNode *head) {
     if(!head||!head->next) 
    return head;
    ListNode*tmp=new ListNode(0);
    tmp->next=head;
    ListNode*p;
    for(p=tmp;p->next&&p->next->next;p=p->next)
    p->next=swapnode(&p->next,&p->next->next);
    return tmp->next;
        
    }
    

    };enter code here


Log in to reply
 

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