思路:
1.二叉树的深度,等于Max(左子树最大深度,右子树最大深度) + 1
2.节点不存在时,此时的深度为0
3.当节点存在,左右子树不存在时(此时为叶子节点) 返回1
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number}
*/
var maxDepth = function(root) {
if(!root) return 0;
if(root.left === null && root.right ===null) return 1
return Math.max(maxDepth(root.left) , maxDepth(root.right)) + 1
};