refactor: review Swift codes for chapter_computational_complexity art… (#396)

* refactor: review Swift codes for chapter_computational_complexity articles

* Update time_complexity.swift

* Update time_complexity.swift

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
nuomi1
2023-03-03 21:22:23 +08:00
committed by GitHub
parent dc72f8b277
commit 17ff091a03
3 changed files with 10 additions and 9 deletions

View File

@ -138,7 +138,7 @@ $$
```swift title=""
// 在某运行平台下
func algorithm(_ n: Int) {
func algorithm(n: Int) {
var a = 2 // 1 ns
a = a + 1 // 1 ns
a = a * 2 // 10 ns
@ -340,19 +340,19 @@ $$
```swift title=""
// 算法 A 时间复杂度:常数阶
func algorithmA(_ n: Int) {
func algorithmA(n: Int) {
print(0)
}
// 算法 B 时间复杂度:线性阶
func algorithmB(_ n: Int) {
func algorithmB(n: Int) {
for _ in 0 ..< n {
print(0)
}
}
// 算法 C 时间复杂度:常数阶
func algorithmC(_ n: Int) {
func algorithmC(n: Int) {
for _ in 0 ..< 1000000 {
print(0)
}