Javascript with recursion


  • 1
    L
    /**
     * @param {ListNode} head
     * @return {ListNode}
     */
    var swapPairs = function(n) {
        if (n === null) {
            return null
        }
        if (n.next === null) {
            return n
        }
        let n1 = n.next
        let n2 = n.next.next
        n1.next = n
        n.next = swapPairs(n2)
        return n1
    };
    

Log in to reply
 

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