Sword Finger Offer-Interview Ideas

Mirror of the binary tree

Operate the given binary tree and transform it into a mirror image of the source binary tree.

Mirror of the binary tree

/* function TreeNode(x) {
  this.val = x;
  this.left = null;
  this.right = null;
} */

function Mirror(root) {
  // write code here
  if (!root) {
    return;
  }
  [root.left, root.right] = [root.right, root.left];
  Mirror(root.left);
  Mirror(root.right);
  return root;
}

Guess you like

Origin www.cnblogs.com/muzidaitou/p/12716567.html