The first time pass at first try..


  • 0
    L

    class Solution {
    public:

    ListNode* swapPairs(ListNode* head) {
        ListNode* one=head;
        head=one;
        while(one&&one->next){
            swap(one->val,(one->next)->val);
            one=(one->next)->next;
        }
        return head;
    }
    

    public:
    void swap(int &x,int &y){

    int temp=0;
    temp=y;
    y=x;
    x=temp;
    

    }

    };


Log in to reply
 

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