Sword refers to Offer 28. Symmetrical binary tree (recursive)

Question
Insert picture description here
Recursively find whether the values ​​of the current left and right nodes are equal and whether the left node of the current left node is equal to the right node of the current right node and the right node of the current left node is equal to the left node of the current right node

    public Boolean recur(TreeNode left ,TreeNode right){
    
    
        if (left == null && right == null) return true;
        if (left == null || right == null) return false;
        return ((left.val == right.val) && recur(left.left,right.right) && recur(left.right,right.left));
    }
    public boolean isSymmetric(TreeNode root) {
    
    
        if (root == null) return true;
        return recur(root.left,root.right);
    }

Guess you like

Origin blog.csdn.net/qq_43434328/article/details/115138823