当前位置:网站首页>Force deduction brush question 101 Symmetric binary tree

Force deduction brush question 101 Symmetric binary tree

2022-04-23 13:56:00 Candy_ Rainbow_

var isSymmetric = function(root) {
    const isTrue = (left, right) => {// Whether the left and right subtrees are mirror images 
        if(left == null && right == null)return true;// Went to the root node 
        if(left == null || right == null)return false;// One of the left and right subtrees is not empty 
        if(left.val != right.val)return false;// The points of symmetry are equal but not equal 
        return isTrue(left.left, right.right) && isTrue(left.right, right.left);// Sub problem 
        
    }
    if(root == null)return true;
    return isTrue(root.left, root.right);
};

版权声明
本文为[Candy_ Rainbow_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231353588847.html