题目地址:
https://www.lintcode.com/problem/double-factorial/description
给定一个正整数nnn,求n!!n!!n!!。
直接按定义求即可。代码如下:
public class Solution {
/*** @param n: the given number* @return: the double factorial of the number*/public long doubleFactorial(int n) {
// Write your code herelong res = 1;while (n > 1) {
res *= n;n -= 2;}return res;}
}
时间复杂度O(n)O(n)O(n),空间O(1)O(1)O(1)。