publicclassSolution { /** * @param n: the given number * @return: the double factorial of the number */publiclongdoubleFactorial(int n) {if (n ==0|| n ==1) return1;return (long)n *doubleFactorial(n -2); }}
Notes
By definition of double factorial, the result is immediate.