美文网首页剑指offer
18-二叉树的镜像

18-二叉树的镜像

作者: 马甲要掉了 | 来源:发表于2020-05-08 20:49 被阅读0次

    题目描述

    操作给定的二叉树,将其变换为源二叉树的镜像。

    输入描述

    .


    image.png

    代码如下:

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

    相关文章

      网友评论

        本文标题:18-二叉树的镜像

        本文链接:https://www.haomeiwen.com/subject/pbiqnhtx.html