mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-09 05:41:47 +08:00
build
This commit is contained in:
@@ -1516,7 +1516,7 @@ $$
|
||||
func bubbleSort(nums: inout [Int]) -> Int {
|
||||
var count = 0 // 计数器
|
||||
// 外循环:待排序元素数量为 n-1, n-2, ..., 1
|
||||
for i in sequence(first: nums.count - 1, next: { $0 > 0 + 1 ? $0 - 1 : nil }) {
|
||||
for i in stride(from: nums.count - 1, to: 0, by: -1) {
|
||||
// 内循环:冒泡操作
|
||||
for j in 0 ..< i {
|
||||
if nums[j] > nums[j + 1] {
|
||||
@@ -2221,7 +2221,7 @@ $$
|
||||
return 1
|
||||
}
|
||||
var count = linearLogRecur(n: n / 2) + linearLogRecur(n: n / 2)
|
||||
for _ in sequence(first: 0, next: { $0 < n - 1 ? $0 + 1 : nil }) {
|
||||
for _ in stride(from: 0, to: n, by: 1) {
|
||||
count += 1
|
||||
}
|
||||
return count
|
||||
|
||||
Reference in New Issue
Block a user