I am trying to reverse a string recursively in Python, however, this solution does not work
def reverseString(self, s):
"""
:type s: List[str]
:rtype: None Do not return anything, modify s in-place instead.
"""
if len(s) == 0:
return s
s[0], s[-1] = s[-1], s[0]
self.reverseString(s[1:-1])
For the sample input ["h","e","l","l","o"], I get the output ["o","e","l","l","h"]. Can anyone exlpain why this does not work?