列表

详情


FED23. 阶乘

描述

请补全JavaScript函数,要求返回数字参数的阶乘。
注意:参数为大于等于0的整数。

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 7ms, 内存消耗: 12928KB, 提交时间: 2022-05-21

{"css":"","js":"function _factorial(number) {\n    // 补全代码\n    return number*2\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1681ms, 内存消耗: 77836KB, 提交时间: 2022-02-08

{"css":"","js":"function _factorial(number) {\n    // 补全代码\n    var  sum= 1 ;\n    for(let i = 1;i<=number;i++){\n        sum *= i\n    }\n    return sum\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1684ms, 内存消耗: 77772KB, 提交时间: 2022-02-09

{"css":"","js":"function _factorial(number) {\n    // 补全代码\n    let sum = 1;\n    while(number>0){\n        sum = number*sum;\n        number--;\n    }\n    return sum;\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1684ms, 内存消耗: 77804KB, 提交时间: 2022-02-09

{"css":"","js":"function _factorial(number) {\n    // 补全代码\n    if(number==1){\n        return number;\n    }\n    return number*_factorial(number-1)\n    \n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1734ms, 内存消耗: 77844KB, 提交时间: 2022-01-23

{"css":"","js":"function _factorial(number) {\n    // 补全代码\n    if(number==0||number==1)\n        return 1;\n    return number*_factorial(number-1)\n}","html":"","libs":[]}

上一题