二叉树的最大深度
更新时间:200726
题目:
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 [25,20,30,28,35]
25 / \ 20 30 / \ 28 35
1
/10第一次加载图片可能有些慢
//函数封装:
BinarySearchTree.prototype.mxaDepthNode = function(node){
if(node == null){
return 0;
}
var leftMaxDepth = this.mxaDepthNode(node.left);
var rightMaxDepth = this.mxaDepthNode(node.right);
return Math.max(leftMaxDepth,rightMaxDepth)+1;
}
完整代码