mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-06 14:27:26 +08:00
Fix: recursion bug for JS and TS (#1028)
This commit is contained in:
@ -20,12 +20,12 @@ function forLoopRecur(n) {
|
||||
const stack = [];
|
||||
let res = 0;
|
||||
// 递:递归调用
|
||||
for (let i = 1; i <= n; i++) {
|
||||
for (let i = n; i > 0; i--) {
|
||||
// 通过“入栈操作”模拟“递”
|
||||
stack.push(i);
|
||||
}
|
||||
// 归:返回结果
|
||||
while (stack.length) {
|
||||
while (stack.length) {
|
||||
// 通过“出栈操作”模拟“归”
|
||||
res += stack.pop();
|
||||
}
|
||||
|
Reference in New Issue
Block a user