剑指 Offer 27. 二叉树的镜像 #
题目 #
给定一棵二叉树,输出其镜像。
思路 #
代码 #
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { this.val = x; }
}
class Solution {
public TreeNode mirrorTree(TreeNode root) {
if (root == null || (root.left == null && root.right == null)) return root;
TreeNode temp = mirrorTree(root.left);
root.left = mirrorTree(root.right);
root.right = temp;
return root;
}
}