104. Maximum Depth of Binary Tree
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.
思路:根节点的最大深度 = 左右子节点中最大深度+1
var maxDepth = function(root) { if(root === null) return 0; var ld = maxDepth(root.left); var rd = maxDepth(root.right); return ld > rd ? ++ld : ++rd; //写法等同于return Math.max(ld,rd)+1; };