二叉树的镜像
题目描述
操作给定的二叉树,将其变换为源二叉树的镜像。
输入描述:
二叉树的镜像定义:源二叉树
解题思路:
将结点的左右子树转换,然后递归其左右子树继续进行。
我的Java代码如下:
/**
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(null == root){
return ;
}else{
TreeNode leftTree = root.left;
root.left = root.right;
root.right = leftTree;
Mirror(root.left);
Mirror(root.right);
return ;
}
}
}
版权声明:本文为博主原创文章,如需转载请注明出处并附上链接,谢谢。
原文地址:http://blog.csdn.net/yannanying/article/details/48066517