My accepted C++ code


  • 0
    R
    class Solution {
    public:
        ListNode* swapPairs(ListNode* head) {
            ListNode* root = head;
            while(root && root->next) {
                swap(root->val, root->next->val);
                root = root->next->next;
            }
            return head;
        }
    };
    

Log in to reply
 

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