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;
var l=maxDepth(root.left);
var r=maxDepth(root.right);
return l>r?l+1:r+1;
};