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.
最大深度是自根节点到最远叶子节点的距离
解题思路:函数递归,分治法,把一个复杂的问题分成更多相同的问题
/**
* 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 === null) {
return 0
}
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right))
};