Simple code for any Newbiee


  • 0
    A
    {
        int temp=*a;
        *a=*b;
        *b=temp;
    }
    
    class Solution {
    public:
        ListNode* swapPairs(ListNode* head) {
            if(!head) return NULL;
            ListNode *curr=head;
            while(curr)
            {
                if(curr->next)
                {
                    swap(&(curr->val),&(curr->next->val));
                    curr=curr->next;
                }
                curr=curr->next;
            }
            return head;
        }
    };

Log in to reply
 

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