JavaScript刷LeetCode -- 104. Maximum Depth of Binary Tree

一、题目

  Given a binary tree, find its maximum depth.

  The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

二、题目大意

  求出二叉树的高度

三、解题思路

  老套路,递归。

四、代码实现

const maxDepth = root => {
  if (!root) {
    return 0
  }
  return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1
}

  如果本文对您有帮助,欢迎关注微信公众号,为您推送更多内容,ε=ε=ε=┏(゜ロ゜;)┛。

猜你喜欢

转载自blog.csdn.net/dai_qingyun/article/details/85083001