--- tags: data_structure_python --- # Reverse String <img src="https://img.shields.io/badge/-easy-brightgreen"> Write a function that reverses a string. The input string is given as an array of characters `char[]`. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. You may assume all the characters consist of printable ascii characters. # Solution ```python= class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ # Time complexity: O(n). # Space complexity: O(n). self.__reverseString(s, 0, len(s)-1) def __reverseString(self, s, beg, end): if beg < end: s[beg], s[end] = s[end], s[beg] self.__reverseString(s, beg+1, end-1) ```