Problem 101 Symmetric Binary Tree
1. Title
2. My initial thoughts and problems
Slightly, look directly at the solution
3. Problem solving method one: recursion
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(q.left,p.right);
}
}