101. 对称二叉树
判断二叉树是否对称
check就完事儿了
/*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode() {}* TreeNode(int val) { this.val = val; }* TreeNode(int val, TreeNode left, TreeNode right) {* this.val = val;* this.left = left;* this.right = right;* }* }*/
class Solution {public boolean Check(TreeNode a, TreeNode b) {if(a == null && b == null) return true;if((a == null && b != null) || (a != null && b==null)) return false;return a.val==b.val && Check(a.left, b.right) && Check(a.right, b.left); }public boolean isSymmetric(TreeNode root) {return Check(root.left, root.right);}
}