Easy Javascript solution


  • 0
    S
    var swapPairs = function(head) {
        var copy = head;
        if(!head ){return [];}
        while(!!head&&head.next){
            var tmp = head.val;
            head.val = head.next.val;
            head.next.val = tmp;
            head = head.next.next;
        }
        return copy;
    };
    

Log in to reply
 

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