LeetCode力扣 101. 对称二叉树 Symmetric Tree 题解代码 JavaScript
程序员文章站
2022-05-16 14:56:04
...
https://leetcode-cn.com/problems/symmetric-tree/
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {boolean}
*/
function isTreeFun(left, right) {
if(!left && !right)
return true;
if(!left || !right)
return false;
if(left.val != right.val)
return false;
return isTreeFun(left.left, right.right) && isTreeFun(left.right, right.left);
}
var isSymmetric = function(root) {
if(!root)
return true;
return isTreeFun(root.left, root.right);
};
上一篇: 力扣101. 对称二叉树(递归、迭代)