K12教育赛事综合服务平台
专注青少年竞赛题库网站
聚乐之家官方网站
下载聚乐之家官方App
int factorialA(int n) { if (n <= 1) return 1; return n * factorialA(n-1); } int factorialB(int n) { if (n <= 1) return 1; int res = 1; for(int i=2; i<=n; i++) res *= i; return res; }
两个函数实现的功能相同。
两个函数的时间复杂度均为O(n)。
factorialA采用递归方式。
factorialB采用递归方式。