leetcode-----101. 对称二叉树
/**
* 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) {
return isSameTree(root, root);
}
public boolean isSameTree(TreeNode p, TreeNode q) {
if (p == null || q== null) return p == q;
return (p.val == q.val) && isSameTree(p.left, q.right) && isSameTree(p.right, q.left);
}
}