🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
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. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7], ![](https://box.kancloud.cn/779da46403721a5d5c4de883047e509e_259x132.png) return its depth = 3. ~~~ function depth(root) { if(root == null) return 0; return Math.max(depth(root.left), depth(root.right)) + 1 } var maxDepth = function(root) { return depth(root) }; ~~~