Question is saying do not return anything that means you need to do inplace reversing. Also this is list of string not a string so whatever you change inside function it will be reflected in the list because lists are mutable.

Correct Solution will be

class Solution:
    def reverseString(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
        s.reverse()

Also If you want to do in your style then correct line will be

s[:] = s[::-1]
Answer from Deepak Tripathi on Stack Overflow
๐ŸŒ
LeetCode
leetcode.com โ€บ problems โ€บ reverse-string
Reverse String - LeetCode
The input string is given as an array of characters s. You must do this by modifying the input array in-place [https://en.wikipedia.org/wiki/In-place_algorithm] with O(1) extra memory.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ reversing a string leetcode question
r/learnpython on Reddit: reversing a string LeetCode question
May 9, 2023 -

So the code goes:

s = [โ€œhโ€, โ€eโ€, โ€lโ€, โ€lโ€, โ€oโ€]

s[:] = s[::-1] print(s)

This prints the reverse of s in both VSCode and on the LeetCode website ide

I tried to see if the follow would work:

s = [โ€œhโ€, โ€eโ€, โ€lโ€, โ€lโ€, โ€oโ€]

s = s[::-1] print(s)

This did work but only on VSCode not on leet code. So my question is why did it work in VSCode and not LeetCode?

Thereโ€™s other solutions I tried to the problem that work in VSCode but not in LeetCode shock I find it odd, am I doing something I shouldn't?

๐ŸŒ
LeetCode
leetcode.com โ€บ problems โ€บ reverse-string-ii
Reverse String II - LeetCode
Reverse String II - Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string. If there are fewer than k characters left, reverse all of them.
๐ŸŒ
DEV Community
dev.to โ€บ ranggakd โ€บ reverse-string-leetcode-python-418m
Reverse String | LeetCode | Python - DEV Community
May 17, 2023 - class Solution: def reverseString(self, s: List[str]) -> None: l = len(s) for i in range(l//2): if s[i] != s[l-1-i]: s[i], s[l-1-i] = s[l-1-i], s[i]
๐ŸŒ
AlgoMonster
algo.monster โ€บ liteproblems โ€บ 344
344. Reverse String - In-Depth Explanation
In-depth solution and explanation for LeetCode 344. Reverse String in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
๐ŸŒ
AlgoMap
algomap.io โ€บ problems โ€บ reverse-string
Reverse String - Leetcode Solution
A naive approach is to use a temporary array to store the reversed characters and then copy them back into the original array. Create a new array T to store the characters in reverse order. Loop from the end of s to the beginning, appending each character to T.
Top answer
1 of 7
4

To do this without space, you need to swap. You can't add array slices. Instead of splitting the indexes in the middle, which will never let you swap opposite pairs (expect in the base case).

You can see it, if you imagine the recursion visually. You start with a list like:

1, 2, 3, 4
^        ^ <-- these need to swap in a reverse

But after your first recursive call you split this into:

---- | ----
1, 2   3, 4
^         ^  <-- these still need to be swapped, bu when?

Now branch one has no way to get at the 4 in branch two to swap unless there's a non-obvious way to do it as the recursion unwinds.

You can instead (much more easily) walk you indexes in from both ends and swap as you go. Then your base case is just when they meet in the middle:

class Solution:
    def reverseString(self, s, lo=0, hi=None):
        if hi == None:
            hi = len(s) - 1

        if hi <= lo:
            return s

        s[lo], s[hi] = s[hi], s[lo]
        return self.reverseString(s, lo + 1, hi - 1)


s = Solution()
s.reverseString([1, 2, 3, 4])
# [4, 3, 2, 1]
s.reverseString([1, 2, 3, 4, 5])
#[5, 4, 3, 2, 1]
2 of 7
1

I am not sure why are you doing recursion. You can simply take two pointers, one at the start and one at the end of the string, start by swapping those characters, and move the pointers towards each other, until they cross, and then you break and return the reversed string.

class Solution:
    def reverseString(self, s):

        if len(s) <= 1: return s
        # The two pointers
        lo = 0
        hi = len(s) - 1
        # Iterate till both pointers cross
        while lo < hi:
            # swap the characters
            tmp = s[lo]
            s[lo] = s[hi]
            s[hi] = tmp
            # increment the pointers
            lo += 1
            hi -= 1
        return s


s = Solution()
print(s.reverseString(['h']))
print(s.reverseString(["h","e","l","l","o"]))
print(s.reverseString(["h","e","l","l","o","w","o","r","l","d"]))
#['h']
#['o', 'l', 'l', 'e', 'h']
#['d', 'l', 'r', 'o', 'w', 'o', 'l', 'l', 'e', 'h']

In addition, the recursive approach for the same is as follows

class Solution:
    def reverseString(self, s, lo=0, hi=None):

        #If one character or less in the string, return the string
        if len(s) <= 1:
            return s

        #The last index should be placed at the end of the string
        if hi == None:
            hi = len(s) - 1

        #If the two indexes cross, return the string
        if hi < lo:
            return s

        #swap the low and high characters
        tmp = s[lo]
        s[lo] = s[hi]
        s[hi] = tmp
        #Recursively call the function
        return self.reverseString(s, lo + 1, hi - 1)

s = Solution()
print(s.reverseString(['h']))
print(s.reverseString(["h","e","l","l","o"]))
print(s.reverseString(["h","e","l","l","o","w","o","r","l","d"]))
#['h']
#['o', 'l', 'l', 'e', 'h']
['d', 'l', 'r', 'o', 'w', 'o', 'l', 'l', 'e', 'h']
Find elsewhere
๐ŸŒ
GitHub
github.com โ€บ kamyu104 โ€บ LeetCode-Solutions โ€บ blob โ€บ master โ€บ Python โ€บ reverse-string.py
LeetCode-Solutions/Python/reverse-string.py at master ยท kamyu104/LeetCode-Solutions
๐Ÿ‹๏ธ Python / Modern C++ Solutions of All 3822 LeetCode Problems (Weekly Update) - LeetCode-Solutions/Python/reverse-string.py at master ยท kamyu104/LeetCode-Solutions
Author ย  kamyu104
๐ŸŒ
LeetCode
leetcode.com โ€บ problems โ€บ reverse-words-in-a-string
Reverse Words in a String - LeetCode
Can you solve this real interview question? Reverse Words in a String - Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters.
๐ŸŒ
Medium
lydiaplu.medium.com โ€บ leetcode-541-reverse-string-ii-24a879b40fdd
LeetCode โ€” 541. Reverse String II | by Pan Lu | Medium
January 31, 2024 - Reversing Characters: The characters between left and right are then reversed using a while loop and a temporary variable for swapping. Returning the Result: After all segments are processed, the character array is returned to a string.
๐ŸŒ
Medium
medium.com โ€บ @dylanzenner โ€บ leetcode-daily-python-344-reverse-string-43efd8e5b005
LeetCode Daily (Python): # 344 Reverse String | by Dylan Zenner | Medium
January 6, 2024 - We then start a loop and basically tell our code to swap the character at the left_pointer with the character at the right_pointer then we update our pointers to progress through the string.
๐ŸŒ
LeetCode
leetcode.com โ€บ problems โ€บ reverse-words-in-a-string-iii
Reverse Words in a String III - LeetCode
Can you solve this real interview question? Reverse Words in a String III - Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Example 1: Input: s = "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc" Example 2: Input: s = "Mr Ding" Output: "rM gniD" Constraints: * 1
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ reverse-a-string
Reverse a String โ€“ Complete Tutorial - GeeksforGeeks
The idea is to start at the last character of the string and move backward, appending each character to a new string res. This new string res will contain the characters of the original string in reverse order.
Published ย  October 3, 2025
๐ŸŒ
Reddit
reddit.com โ€บ r/python โ€บ 7 proven methods to reverse the python string in 2021
r/Python on Reddit: 7 proven methods to reverse the python string in 2021
December 4, 2021 -

How to reverse the python string now in 2021?

Hello to all python buddies,

You're stirring your cofee, and going to read r/Python. And you love the blog post.

Today, I'm going to make r/Python more lovable to you.

I'm going to show you the 6 proven methods to reverse the python string. Which are easy and quick to do.

So, start these methods

โ˜บ๏ธ

  1. Reverse the string using slice method

You can reverse the string using slice method.

The slice indicates the [start:end] position.

A start is a position where sequence start. and end is the position where sequence ends.

The first position is 0th index.

So, here you can use [::-1].

The [::-1] means sequence starting from last of the string.

For example,

a = ["hello"]

print(a[::-1])

It'll reverse the python string.

>>> olleh

2. Reversed the string using reversed() &join() methods

First of all, the reversed() method reverse the sequence.

After reversed() with you can join() every iterables as string.

Basically, the join() method join the iterables as a string seperator.

reversed() & join()

After running, this code you'll get something like

๐Ÿ‘‡

output

3. Reversed the string: join() and sorted() method

As you know, sorted() sort the string or sequences in ascending or descending method.

Here, I'm going to use descending order.

For descending order, pass reverse = True inside sorted().

And previously, I've told that join joins the sequences as a string seperator.

For example,

join() & sorted()

Here, you can see that first I've sorted the string in descending order.

After that, I've join every character as a string.

When you run above code, you'll get:--->

output

So, you've get the reversed string as output.

4. Reversed the string using for loop

You can reverse the string using for loop.

To create the reverse string in for loop, you need function with empty string.

The every new string add to the empty string.

After adding, all the string it becomes the reverse string.

For example,

code

After running code, you'll get--->

output

So, here you've seen how to reverse the python string. I've told you the 6 methods.

And here I've shown you the 4 methods.

But I'm going to show you 3 methods more.

That means 7 method for reverse the python string.

So, I've given you 1 bonus method.

To get these 3 methods, check out the

๐Ÿ‘‡

https://www.heypython.com/python-programming/reverse-the-python-string/

๐ŸŒ
AlgoMonster
algo.monster โ€บ liteproblems โ€บ 151
151. Reverse Words in a String - In-Depth Explanation
In-depth solution and explanation for LeetCode 151. Reverse Words in a String in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.