题目要求
给定一个二叉树,将其变换为源二叉树的镜像。
核心思想
递归思想,分治调用。
完整代码如下
public class Solution {
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int val) {
this.val = val;
}
}
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);
}
}