¡GoConqr estrena diseño! Cuéntanos qué te parece.

Fichas

Mirror BST

Suhas S Inglés 1 ficha

Fichas del conjunto (1)

  1. 1Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1class Solution {
    public TreeNode invertTree(TreeNode root) {
    if(root ==null) {
    return root;
    }
    root=invertOperation(root,root.left,root.right);
    return root;
    }
    public TreeNode invertOperation(TreeNode root,TreeNode left,TreeNode right) {
    if(root ==null) {
    return root;
    }
    if(left!=null) {
    invertOperation(left,left.left,left.right);
    }
    TreeNode temp=new TreeNode(0);
    temp=root.left;//temp=1
    root.left=root.right;//left=3
    root.right=temp;//right=1
    if(right!=null) {
    invertOperation(right,right.left,right.right);
    }
    return root;
    }
    }

Información

Descripción
Fichas sobre Mirror BST, creado por Suhas S el 12/05/2018.
Creado por
Suhas S
Visitas
0
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?