美文网首页
最N叉树的最大深度?

最N叉树的最大深度?

作者: 一个被程序员耽误的厨师 | 来源:发表于2021-02-19 15:45 被阅读0次

/**
 * 最N叉树的最大深度?
 * @param {*} val 
 * @param {*} children 
 */

 var maxDepth = function(root){
   if(root === null) return 0;

   let depthLeft = maxDepth(root.left);

   let depthRight = maxDepth(root.right);

   return Math.max(depthLeft,depthRight)+1;
 }


console.log(maxDepth(a));

相关文章

网友评论

      本文标题:最N叉树的最大深度?

      本文链接:https://www.haomeiwen.com/subject/ftiractx.html