添加 344.反转字符串 Swift版本

This commit is contained in:
极客学伟
2021-09-10 17:21:54 +08:00
parent e9f48c211a
commit c33f8452a8

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)