题目描述
操作给定的二叉树,将其变换为源二叉树的镜像。
分析:镜像的递归定义就是将原有二叉树中节点的左右子树对调。代码如下:
1 /**
2 public class TreeNode {
3 int val = 0;
4 TreeNode left = null;
5 TreeNode right = null;
6
7 public TreeNode(int val) {
8 this.val = val;
9
10 }
11
12 }
13 */
14 public class Solution {
15 public void Mirror(TreeNode root) {
16 if(root==
null){
17 return ;
18 }
19 TreeNode temp ;
20 temp =
root.left ;
21 root.left =
root.right ;
22 root.right =
temp ;
23 Mirror(root.left) ;
24 Mirror(root.right) ;
25 }
26 }
转载于:https://www.cnblogs.com/huntertoung/p/4777278.html