Add Swift language blocks to the docs.

This commit is contained in:
Yudong Jin
2023-01-08 19:41:05 +08:00
parent 3ba37dba3a
commit 73e3452838
22 changed files with 414 additions and 70 deletions

View File

@@ -210,6 +210,12 @@ $$
}
```
=== "Swift"
```swift title="binary_search.swift"
```
### “左闭右开”实现
当然,我们也可以使用“左闭右开”的表示方法,写出相同功能的二分查找代码。
@@ -374,6 +380,12 @@ $$
}
```
=== "Swift"
```swift title="binary_search.swift"
```
### 两种表示对比
对比下来,两种表示的代码写法有以下不同点:
@@ -460,6 +472,12 @@ $$
int m = i + (j - i) / 2;
```
=== "Swift"
```swift title=""
```
## 复杂度分析
**时间复杂度 $O(\log n)$ ** 其中 $n$ 为数组或链表长度;每轮排除一半的区间,因此循环轮数为 $\log_2 n$ ,使用 $O(\log n)$ 时间。