描述
求给定二叉树的最大深度,
最大深度是指树的根结点到最远叶子结点的最长路径上结点的数量。
/*
* function TreeNode(x) {
* this.val = x;
* this.left = null;
* this.right = null;
* }
*/
/**
*
* @param root TreeNode类
* @return int整型
*/
function maxDepth( root ) {
// write code here
if(!root) return 0;
return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1
// 深度遍历+递归 +1是root节点
}
module.exports = {
maxDepth : maxDepth
};