当前位置: 代码迷 >> 综合 >> 【Lintcode】771. Double Factorial
  详细解决方案

【Lintcode】771. Double Factorial

热度:97   发布时间:2024-02-25 16:44:43.0

题目地址:

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)

  相关解决方案