建立镜像二叉树

图片说明

/* function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
} */
function Mirror(root)
{
    // write code here
    if(!root) return null
    function buildImage(root){
        if(!root.left && !root.right) return
        var temp = root.left
        root.left = root.right
        root.right = temp
        if(root.left) buildImage(root.left)
        if(root.right) buildImage(root.right)
    }
    buildImage(root)
    return root
}
树算法 文章被收录于专栏

树相关算法

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 17:58
点赞 评论 收藏
分享
05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务