Merge pull request #735 from qxuewei/master

添加 344.反转字符串 Swift版本
This commit is contained in:
程序员Carl
2021-09-12 10:21:49 +08:00
committed by GitHub

View File

@ -206,6 +206,7 @@ var reverseString = function(s) {
Swift:
```swift
// 双指针 - 元组
func reverseString(_ s: inout [Character]) {
var l = 0
var r = s.count - 1
@ -216,11 +217,18 @@ func reverseString(_ s: inout [Character]) {
r -= 1
}
}
// 双指针法 - 库函数
func reverseString(_ s: inout [Character]) {
var j = s.count - 1
for i in 0 ..< Int(Double(s.count) * 0.5) {
s.swapAt(i, j)
j -= 1
}
}
```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频[代码随想录](https://space.bilibili.com/525438321)