mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-02 10:13:00 +08:00
build
This commit is contained in:
@@ -1631,7 +1631,7 @@ comments: true
|
||||
var stack: [Int] = []
|
||||
var res = 0
|
||||
// 递:递归调用
|
||||
for i in stride(from: n, to: 0, by: -1) {
|
||||
for i in (1 ... n).reversed() {
|
||||
// 通过“入栈操作”模拟“递”
|
||||
stack.append(i)
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ $$
|
||||
|
||||
// 算法 C 的时间复杂度:常数阶
|
||||
func algorithmC(n: Int) {
|
||||
for _ in 0 ..< 1000000 {
|
||||
for _ in 0 ..< 1_000_000 {
|
||||
print(0)
|
||||
}
|
||||
}
|
||||
@@ -1784,7 +1784,7 @@ $$
|
||||
func bubbleSort(nums: inout [Int]) -> Int {
|
||||
var count = 0 // 计数器
|
||||
// 外循环:未排序区间为 [0, i]
|
||||
for i in stride(from: nums.count - 1, to: 0, by: -1) {
|
||||
for i in nums.indices.dropFirst().reversed() {
|
||||
// 内循环:将未排序区间 [0, i] 中的最大元素交换至该区间的最右端
|
||||
for j in 0 ..< i {
|
||||
if nums[j] > nums[j + 1] {
|
||||
|
||||
Reference in New Issue
Block a user