class Solution {
public boolean isSymmetric(TreeNode root) {
return check(root, root);
}
public boolean check(TreeNode p, TreeNode q) {#确定函数的参数与返回值
if (p == null && q == null) {#确定终止条件
return true;
}
if (p == null || q == null) {#终止条件
return false;
}
return p.val == q.val && check(p.left, q.right) && check(p.right, q.left);#单层递归逻辑
}
}
网友评论