二叉树的镜像

来源:互联网 发布:虚荣英雄数据 编辑:程序博客网 时间:2024/05/28 05:16

题目

这里写图片描述

思路

交换
递归
root为空则返回

代码

public class Solution {    public void Mirror(TreeNode root) {        if(root==null)            return;        TreeNode temp = new TreeNode(0);        temp = root.left;        root.left = root.right;        root.right = temp;        Mirror(root.left);        Mirror(root.right);        return;    }
原创粉丝点击