二叉树的镜像

二叉树的镜像

http://www.nowcoder.com/questionTerminal/564f4c26aa584921bc75623e48ca3011

public class Solution {
public void Mirror(TreeNode root) {

    //递归返回条件
    if(root==null){
        return;
    }

    //存下来左右结点
   TreeNode tempLeft = root.left;
   TreeNode tempRight = root.right;

    //交换
    root.left = tempRight;
    root.right = tempLeft;

    //左递归
    Mirror(tempLeft);
    //右递归
    Mirror(tempRight);

}

}

全部评论

相关推荐

昨天 12:25
重庆大学 C++
到底要什么样的学历才配进呢
投递速腾聚创等公司7个岗位
点赞 评论 收藏
分享
炫哥_:为什么都读硕士了?项目还是网上的项目(真心发问)
最后再改一次简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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