题解 | #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
};
全部评论

相关推荐

叁六玖:你看,最后不是让你加油,就是鼓励你,还祝福你求职顺利。
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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