题目描述
输入一个二叉树,输出其镜像。
分类:二叉树,递归
解法1:对于某个节点,先交换其左右子节点,然后对于左右子节点进行递归操作
分类:二叉树,递归
解法1:对于某个节点,先交换其左右子节点,然后对于左右子节点进行递归操作
/**
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(root==null) return;
TreeNode t = root.left;
root.left = root.right;
root.right = t;
Mirror(root.left);
Mirror(root.right);
}
}