diff --git a/codes/cpp/chapter_computational_complexity/iteration.cpp b/codes/cpp/chapter_computational_complexity/iteration.cpp index 16d9e1e0f..f17a27e85 100644 --- a/codes/cpp/chapter_computational_complexity/iteration.cpp +++ b/codes/cpp/chapter_computational_complexity/iteration.cpp @@ -23,7 +23,7 @@ int whileLoop(int n) { // 循环求和 1, 2, ..., n-1, n while (i <= n) { res += i; - i += 1; // 更新条件变量 + i++; // 更新条件变量 } return res; } @@ -32,12 +32,12 @@ int whileLoop(int n) { int whileLoopII(int n) { int res = 0; int i = 1; // 初始化条件变量 - // 循环求和 1, 2, 4, 5... + // 循环求和 1, 4, ... while (i <= n) { res += i; - i += 1; // 更新条件变量 - res += i; - i *= 2; // 更新条件变量 + // 更新条件变量 + i++; + i *= 2; } return res; } diff --git a/codes/java/chapter_computational_complexity/iteration.java b/codes/java/chapter_computational_complexity/iteration.java index 4f1293fca..fd628db14 100644 --- a/codes/java/chapter_computational_complexity/iteration.java +++ b/codes/java/chapter_computational_complexity/iteration.java @@ -24,7 +24,7 @@ public class iteration { // 循环求和 1, 2, ..., n-1, n while (i <= n) { res += i; - i += 1; // 更新条件变量 + i++; // 更新条件变量 } return res; } @@ -33,12 +33,12 @@ public class iteration { public static int whileLoopII(int n) { int res = 0; int i = 1; // 初始化条件变量 - // 循环求和 1, 2, 4, 5... + // 循环求和 1, 4, ... while (i <= n) { res += i; - i += 1; // 更新条件变量 - res += i; - i *= 2; // 更新条件变量 + // 更新条件变量 + i++; + i *= 2; } return res; } diff --git a/codes/python/chapter_computational_complexity/iteration.py b/codes/python/chapter_computational_complexity/iteration.py index 596a9960d..2f8339841 100644 --- a/codes/python/chapter_computational_complexity/iteration.py +++ b/codes/python/chapter_computational_complexity/iteration.py @@ -29,12 +29,12 @@ def while_loop_ii(n: int) -> int: """while 循环(两次更新)""" res = 0 i = 1 # 初始化条件变量 - # 循环求和 1, 2, 4, 5... + # 循环求和 1, 4, ... while i <= n: res += i - i += 1 # 更新条件变量 - res += i - i *= 2 # 更新条件变量 + # 更新条件变量 + i += 1 + i *= 2 return res diff --git a/mkdocs.yml b/mkdocs.yml index 1e4ad5f52..c92d8f3d9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -148,6 +148,7 @@ nav: # [icon: material/timer-sand] - chapter_computational_complexity/index.md - 2.1   算法效率评估: chapter_computational_complexity/performance_evaluation.md + # [status: new] - 2.2   迭代与递归: chapter_computational_complexity/iteration_and_recursion.md - 2.3   时间复杂度: chapter_computational_complexity/time_complexity.md - 2.4   空间复杂度: chapter_computational_complexity/space_complexity.md