剑指offer(18)二叉树镜像

/**
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
public class Solution {
    public void Mirror(TreeNode root) {
        if(root == null){return;}
        if(root.left == null && root.right == null){return;}
        TreeNode node = root.left;
        root.left = root.right;
        root.right = node;
        if(root.left!=null){Mirror(root.left);}
        if(root.right!=null){Mirror(root.right);}
        
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
_mos_:我以为手抄报简历就已经很顶了,没想到还有表格简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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