/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public boolean isSymmetric(TreeNode root) {
if(root == null){
return true;
}
return isMirror(root,root);
}
public boolean isMirror(TreeNode left,TreeNode right){
boolean flag =false;
if(left == null && right == null){
return true;
}
if(left == null || right == null){
return false;
}
if(left.val != right.val){
return false;
}
if(left.val == right.val){
flag = (isMirror(left.left,right.right) && isMirror(left.right,right.left));
}
return flag;
}
}
用递归的方法去做。。挺简单的,正常的逻辑。