zl程序教程

您现在的位置是:首页 >  其他

当前栏目

每日一题---力扣剑指Offer 27.二叉树的镜像(Java)

2023-03-14 22:49:11 时间

代码

public TreeNode mirrorTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        TreeNode temp;
        temp = root.left;
        root.left = root.right;
        root.right = temp;
        mirrorTree(root.left);
        mirrorTree(root.right);
        return root;
    }

消耗

image