题解 | #对称的二叉树#

对称的二叉树

http://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb

/* function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
} */
function isSymmetrical(pRoot)
{
  if(pRoot === null) return true
  function compare(node1, node2) {
      if(node1 === null && node2 === null) return true
      if(node1 === null || node2 === null) return false
      if(node1.val !== node2.val) return false
      return compare(node1.left, node2.right) && compare(node1.right, node2.left)
  }
  return compare(pRoot.left, pRoot.right)
}
module.exports = {
    isSymmetrical : isSymmetrical
};
// 1 2 3 4 2 4 3
全部评论

相关推荐

02-10 12:23
已编辑
新余学院 C++
采集想要offer:专业技能那里要一条一条的列出来吧,感觉你项目很厉害了,但是如果你不写技术栈面试官对你项目不太懂的话都没办法问你八股😂C++都是基架岗,都是一群9✌🏻在卷,我觉得你要是有时间学个go把MySQL和redis写上去找个开发岗吧
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务