Playing Hacks and Stuffs!
We are to reverse a string without using memory this method is called in-place
algorithm
Basically the idea to solve this is:
s[i], s[n-i-1] = s[n-i-1], s[i]
There are other ways to reverse a string but this method changes the value in memory and does not require much memory usage
Solve Script: link
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
n = len(s)
for i in range(n//2):
s[i], s[n-i-1] = s[n-i-1], s[i]