一、题目地址
二、具体代码
/*
* function TreeNode(x) {
* this.val = x;
* this.left = null;
* this.right = null;
* }
*/
/**
*
* @param root TreeNode类
* @return int整型
*/
//深度遍历 + 递归
function maxDepth( root ) {
if(!root) {
return 0;
}
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
module.exports = {
maxDepth : maxDepth
};