104. 二叉树的最大深度
var maxDepth = function (root) { if (!root) return 0; let res = 0; const dfs = (root, l) => { if (!root) return; if (!root.left && !root.right) { res = Math.max(l, res); } dfs(root.left, l + 1); dfs(root.right, l + 1); }; dfs(root, 1); return res; };

浙公网安备 33010602011771号