mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-06 05:48:58 +08:00
Several bug fixes and improvements (#945)
* Update Dockerfile for code debugging. * Format Python code using Black. * Improve dark theme by defining html classes for the figures, animations and cover images. * Fix several glossary translation. * Update a code comment. * Fix climbing_stairs_backtrack: the pruning should not require the sorted choices list. * Update the code of array and list traversal. * Fix a rendering issue of README.md * Update code of list traversal. * Fix array_definition.png * Update README.md * Fix max_capacity_moving_short_board.png * Fix array.dart * Fix array.dart * Fix array.dart * Fix array.dart
This commit is contained in:
@ -52,7 +52,7 @@ void traverse(int *nums, int size) {
|
||||
int count = 0;
|
||||
// 通过索引遍历数组
|
||||
for (int i = 0; i < size; i++) {
|
||||
count++;
|
||||
count += nums[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ int main() {
|
||||
printVector(nums);
|
||||
|
||||
/* 访问元素 */
|
||||
int x = nums[1];
|
||||
cout << "访问索引 1 处的元素,得到 x = " << x << endl;
|
||||
int num = nums[1];
|
||||
cout << "访问索引 1 处的元素,得到 num = " << num << endl;
|
||||
|
||||
/* 更新元素 */
|
||||
nums[1] = 0;
|
||||
@ -49,13 +49,12 @@ int main() {
|
||||
/* 通过索引遍历列表 */
|
||||
int count = 0;
|
||||
for (int i = 0; i < nums.size(); i++) {
|
||||
count++;
|
||||
count += nums[i];
|
||||
}
|
||||
|
||||
/* 直接遍历列表元素 */
|
||||
count = 0;
|
||||
for (int n : nums) {
|
||||
count++;
|
||||
for (int x : nums) {
|
||||
count += x;
|
||||
}
|
||||
|
||||
/* 拼接两个列表 */
|
||||
|
@ -16,7 +16,7 @@ void backtrack(vector<int> &choices, int state, int n, vector<int> &res) {
|
||||
for (auto &choice : choices) {
|
||||
// 剪枝:不允许越过第 n 阶
|
||||
if (state + choice > n)
|
||||
break;
|
||||
continue;
|
||||
// 尝试:做出选择,更新状态
|
||||
backtrack(choices, state + choice, n, res);
|
||||
// 回退
|
||||
|
Reference in New Issue
Block a user