Solución
solution.tsTypeScript
interface TreeNode {
value: number;
left: TreeNode | null;
right: TreeNode | null;
}
function maxDepth(root: TreeNode | null): number {
// Tu código aquí
if (root === null) return 0;
let profundidadIzquierda = maxDepth(root.left);
let profundidadDerecha = maxDepth(root.right);
return Math.max(profundidadDerecha, profundidadIzquierda) + 1;
}
// No modificar: necesario para evaluar el resultado.
export { maxDepth };
0respuestas