美文网首页
剑指offer--18. 二叉树的镜像

剑指offer--18. 二叉树的镜像

作者: yui_blacks | 来源:发表于2018-12-11 22:16 被阅读0次

题目:
操作给定的二叉树,将其变换为源二叉树的镜像。

思路:
递归

public class Solution {
    public void Mirror(TreeNode root) {
        if(root == null)
            return;
        if(root.left == null && root.right == null)
            return;
         
        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;

        Mirror(root.left);
        Mirror(root.right);
    }
}

相关文章

网友评论

      本文标题:剑指offer--18. 二叉树的镜像

      本文链接:https://www.haomeiwen.com/subject/madyhqtx.html