Inicio/Foro/Factorial/Discusión
Solución

@adriantalonia11_d49a8106·6/8/2026TypeScript
solution.tsTypeScript
public class Solution {
    public int factorial(int value) {
        /* improve
        if (value < 0) {
            throw new IllegalArgumentException(
                "Factorial is not defined for negative integers"
            );
        }
        */

        if (value == 0 || value == 1) return 1;


        int result = 1;

        for (int i = 2; i <= value; i++) {
            result *= i;
        }

        return result;
    }
}
0respuestas
Respuestas

Aún no hay respuestas

¡Sé el primero en responder!

Escribir un comentario

Recuerda ser amable. Estás comentando la solución de otra persona. Comparte tu perspectiva de forma constructiva y respetuosa.

Debes iniciar sesión para publicar un comentario.