Merge pull request #233 from mellowrsa/patch-1

Update time_complexity.md
This commit is contained in:
Yudong Jin 2023-01-11 02:46:11 +08:00 committed by GitHub
commit cbede422e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1434,12 +1434,15 @@ $$
for (int i = n - 1; i > 0; i--) { for (int i = n - 1; i > 0; i--) {
// 内循环:冒泡操作 // 内循环:冒泡操作
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
if (nums[j] > nums [j + 1])
{
// 交换 nums[j] 与 nums[j + 1] // 交换 nums[j] 与 nums[j + 1]
int tmp = nums[j]; int tmp = nums[j];
nums[j] = nums[j + 1]; nums[j] = nums[j + 1];
nums[j + 1] = tmp; nums[j + 1] = tmp;
count += 3; // 元素交换包含 3 个单元操作 count += 3; // 元素交换包含 3 个单元操作
} }
}
} }
return count; return count;