➜ ~

Playing Hacks and Stuffs!


Project maintained by h4ckyou Hosted on GitHub Pages — Theme by mattgraham

Reverse String

image

We are to reverse a string without using memory this method is called in-place algorithm

Basically the idea to solve this is:

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 image

Leetcode Submission Script

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]