你会如何编写一个非递归算法来计算 n!
?
最佳答案
因为任何大于 12 的 Int32 都会溢出!无论如何,就这样做:
public int factorial(int n) {
int[] fact = {1, 1, 2, 6, 24, 120, 720, 5040, 40320,
362880, 3628800, 39916800, 479001600};
return fact[n];
}
关于algorithm - 您将如何编写非递归算法来计算阶乘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/231250/