题目

给出一个二叉树,输出他的镜像二叉树

思路

交换左右节点,递归

代码

/* function TreeNode(x) { this.val = x; this.left = null; this.right = null; } */
function Mirror(root) {
  if (root === null) return;
  Mirror(root.left);
  Mirror(root.right);
  [root.left, root.right] = [root.right, root.left];
  return root;
}