A recursion Javascript solution


  • 0
    var invertTree = function(root) {
        if(root!==null && (root.left!==null || root.right!==null)){
            var tmp;
            tmp = root.left;
            root.left = root.right;
            root.right = tmp;
            invertTree(root.left);
            invertTree(root.right);
        }
        return root;
    };
    

Log in to reply
 

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