Simple JavaScript solution


  • 0
    M
    var invertTree = function(root) {
        if (root) {
            const left = root.left || null;
            const right = root.right || null;
            root.left = invertTree(right);
            root.right = invertTree(left);
        }
        return root;
    };
    

Log in to reply
 

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