题解 | #28.二叉树的最大深度#

二叉树的最大深度

http://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73

没什么可说的,递归求深度,空返回0,否则返回max(左子树,右子树)+1

function maxDepth( root ) {
  if(root == null)
    return 0;
  return Math.max( maxDepth(root.left), maxDepth(root.right) ) + 1;
}
module.exports = {
    maxDepth : maxDepth
};
全部评论

相关推荐

11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务