题解 | #对称的二叉树#

对称的二叉树

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
全部评论

相关推荐

来个offer吧求求求了:校园经历和要找到工作有半毛钱关系?
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务