Reverse String
String Simulation
Problem
Thought Process
Solution
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
left, right = 0, len(s)-1
while(left<right):
s[left], s[right] = s[right], s[left]
left+=1
right-=1
return s
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
self.revString(s, 0)
def revString(self, s, i):
n = len(s)
if i == n//2:
return
s[i], s[n-i-1] = s[n-i-1], s[i]
self.revString(s, i+1)Time Complexity
Last updated