题解:
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public TreeNode mirrorTree(TreeNode root) {
if(root==null){
return root;
}
if(root.left!=null || root.right!=null){
TreeNode tmp=root.left;
root.left = root.right;
root.right = tmp;
}
mirrorTree(root.left);
mirrorTree(root.right);
return root;
}
}