File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
src/main/java/com/thealgorithms/divideandconquer Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 11package com .thealgorithms .divideandconquer ;
2+
23/**
34 * Computes the factorial of a non-negative integer using an iterative
45 * approach to avoid recursion overhead and stack overflow risks.
1011 * <p>Time Complexity: O(n)
1112 * <br>Space Complexity: O(1)
1213 */
13- public class Factorial {
14+ public final class Factorial {
15+
16+ private Factorial () {
17+ // Utility class
18+ }
19+
1420 /**
1521 * Returns the factorial of the given non-negative number.
1622 *
1723 * @param n the number to compute factorial for
1824 * @return factorial of n (n!)
1925 * @throws IllegalArgumentException if n is negative
2026 */
21- private Factorial () {
22- // Utility class
23- }
2427 public static long factorial (long n ) {
2528 if (n < 0 ) {
2629 throw new IllegalArgumentException ("Negative input not allowed" );
@@ -34,3 +37,4 @@ public static long factorial(long n) {
3437 return result ;
3538 }
3639}
40+
You can’t perform that action at this time.
0 commit comments