mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-23 09:42:28 +08:00
build
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user