码迷,mamicode.com
首页 > 其他好文 > 详细

二叉树的镜像

时间:2020-07-18 15:54:16      阅读:51      评论:0      收藏:0      [点我收藏+]

标签:二叉树   nod   loading   ||   int   http   efi   turn   镜像   

技术图片

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public TreeNode mirrorTree(TreeNode root) {
        if(root == null) return null;

        if(root.left!=null||root.right!=null){
            TreeNode tmp = root.left;
            root.left = root.right;
            root.right = tmp;
            mirrorTree(root.left);
            mirrorTree(root.right);
        }
        return root;

    }
}

技术图片

二叉树的镜像

标签:二叉树   nod   loading   ||   int   http   efi   turn   镜像   

原文地址:https://www.cnblogs.com/cstdio1/p/13335775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!