leetcode -- 101. Symmetric Tree
题目描述
题目难度:Easy
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
AC代码
class Solution {
public boolean isSymmetric(TreeNode root) {
if(root == null) return true;
return isSymmetric(root.left, root.right);
}
private boolean isSymmetric(TreeNode p, TreeNode q){
if(p == null && q == null) return true;
if(p == null || q == null) return false;
if(p.val == q.val) return isSymmetric(p.left, q.right) && isSymmetric(p.right, q.left);
return false;
}
}