My solution in JavaScript


  • 0
    B

    /**

    • Definition for a binary tree node.
    • function TreeNode(val) {
    • this.val = val;
      
    • this.left = this.right = null;
      
    • }
      /
      /
      *
    • @param {TreeNode} root
    • @return {TreeNode}
      */
      var invertTree = function(root) {
      if (root === null)
      return root;
      var temp = root.left;
      root.left = root.right;
      root.right =temp;
      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.