Problem
Write a function that reverses a string. The input string is given as an array of characters s.
You must do this by modifying the input array in-place with O(1) extra memory.
Algorithm
Just exchange the i th item with the len(s)-1-i th item.
Code
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
slen = len(s)
for i in range(slen // 2):
temp = s[i]
s[i] = s[slen-1-i]
s[slen-1-i] = temp