3 lines JavaScript


  • 0
    F

    Depth First Search traversal, on-place swap.

    var invertTree = function(root) {
        if (!root) { return root; }
        [root.left, root.right] = [invertTree(root.right), invertTree(root.left)]
        return root;
    };
    

Log in to reply
 

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