题解 | #对称的二叉树# 超简短代码
对称的二叉树
https://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb
对称,就是左右相同,原理简单,需要理解,超简短代码
/* function TreeNode(x) { this.val = x; this.left = null; this.right = null; } */ function isSymmetrical(pRoot) { // write code here : return !pRoot||fn(pRoot.left, pRoot.right); } function fn(a, b) { return (!a && !b) || (a && b && a.val == b.val && fn(a.left, b.right) && fn(a.right, b.left)) ; } module.exports = { isSymmetrical: isSymmetrical, };