This commit is contained in:
krahets
2024-01-07 23:42:54 +08:00
parent 09faf59716
commit 4c553058fb
48 changed files with 501 additions and 138 deletions

View File

@ -1652,12 +1652,12 @@ Therefore, **we can use an explicit stack to simulate the behavior of the call s
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();
}
@ -1675,12 +1675,12 @@ Therefore, **we can use an explicit stack to simulate the behavior of the call s
const stack: number[] = [];
let res: number = 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();
}