Solution:
Time complexity: O(n)
Space complexity: O(1)
Code:
class Solution {
func reverseString(_ s: inout [Character]) {
if s.count == 0 {
return
}
var left = 0
var right = s.count - 1
while left < right {
s.swapAt(left, right)
left += 1
right -= 1
}
}
}
Follow me on:
Comments