Problem 101 Symmetric Binary Tree

1. Title

Insert picture description here

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);

    }
}

Insert picture description here

4. Problem solving method two

Guess you like

Origin blog.csdn.net/ambitionLlll/article/details/115300738