用变量记录下最大深度,在深度优先遍历过程中遇到了叶子结点就进行最大深度的更新 function maxDepth( root ) { // write code here let max = 0; const dfs = (n,l)=>{ //递归出口 if(!n) {return;} // 若当前节点是叶子结点就进行更新最大值 if(!n.left && !n.right){ max = Math.max(max,l) } dfs(n.left,l+1); dfs(n.right,l+1); } dfs(root,1) return max; } module.expo...