剑指offer 26. 树的子结构
class Solution {
public boolean isSubStructure(TreeNode A, TreeNode B) {
return (A != null && B != null) && (recur(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B));
}
public boolean recur(TreeNode A, TreeNode B){
if(B == null) return true;
if(A == null || A.val != B.val) return false;
return recur(A.left, B.left) && recur(A.right, B.right);
}
}
剑指offer 27.二叉树的镜像
class Solution {
public TreeNode mirrorTree(TreeNode root) {
if(root != null){
TreeNode tmp = root.left;
root.left = root.right;
root.right = tmp;
mirrorTree(root.left);
mirrorTree(root.right);
}
return root;
}
}
剑指offer 28.对称的二叉树
class Solution {
public boolean isSymmetric(TreeNode root) {
return root == null ? true : recur(root.left, root.right);
}
public boolean recur(TreeNode L, TreeNode R){
if(L == null && R == null){
return true;
}
if(L == null || R == null || L.val != R.val){
return false;
}
return recur(L.left, R.right) && recur(L.right, R.left);
}
}



