LeetCode/swift/reverse-string.swift
Matej Focko 81e5186b71
swift: add «344. Reverse String»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-06-02 10:50:48 +02:00

8 lines
197 B
Swift

class Solution {
func reverseString(_ s: inout [Character]) {
for i in 0..<(s.count / 2) {
let j = s.count - i - 1
(s[i], s[j]) = (s[j], s[i])
}
}
}