题目主要来源:LeetCode。主要选自剑指offer、程序员面试宝典。 每日尽可能保持 N+1 道题,N 取 0 到 9。
部分解法是从LeetCode上大佬们的解法中拿过来的,如有侵权,告知立删
public class JZ27 {
public TreeNode mirrorTree(TreeNode root) {
if (root == null) return null;
TreeNode temp = root.left;
root.left = root.right;
root.right = temp;
mirrorTree(root.right);
mirrorTree(root.left);
return root;
}
}
public class JZ28 {
public boolean isSymmetric(TreeNode root) {
return root == null || recur(root.left, root.right);
}
private boolean recur(TreeNode left, TreeNode right) {
if (left == null && right == null) return true;
if (left == null || right == null || left.val != right.val) return false;
return recur(left.left, right.right) && recur(left.right, right.left);
}
}
public class JZ20 {
}
|