You are viewing a single comment's thread. Return to all comments →
My Java solution with linear time and constant space:
public static void extraLongFactorials(int n) { BigInteger factorial = calculateFactorial(n); System.out.println(factorial); } public static BigInteger calculateFactorial(int n){ BigInteger result = BigInteger.ONE; for(int i = 2; i <= n; i++){ result = result.multiply(BigInteger.valueOf(i)); } return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Extra Long Factorials
You are viewing a single comment's thread. Return to all comments →
My Java solution with linear time and constant space: