título Descripción
El funcionamiento de un árbol binario dado, el árbol binario se convierte una imagen de origen en.
Introduzca una descripción:
二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ 11 9 7 5
El propósito de esta pregunta es realmente muy simple idea, siempre y cuando nos recursiva atravesar el árbol binario de origen, luego a la izquierda y la derecha subárboles nodo de conmutación hacia abajo hasta el final del proceso Consideremos el siguiente ejemplo:
/* function TreeNode(x) {
this.val = x;
this.left = null;
this.right = null;
} */
function Mirror(root)
{
function change(head){
if(!head){return false;}
let temp = head.left;
head.left = head.right;
head.right = temp;
change(head.left);
change(head.right);
}
change(root);
return root;
}