判断一个二叉树,是否是左右对称的,思路:使用递归方法:

/**
* Definition for a binary tree node.
* public class TreeNode {
* public int val;
* public TreeNode left;
* public TreeNode right;
* public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
public class Solution {
public bool IsSymmetric(TreeNode root) {
return Check(root,root);
}
bool Check(TreeNode left,TreeNode right){
if(left==null && right == null)
return true;
else if(left == null || right == null)
return false;
bool r = left.val == right.val;
return r && Check(left.left,right.right) && Check(left.right,right.left);
}
}