Talentd
FleetCode

344. Reverse String

Easy81.2% acceptance16 companies

Write a function that reverses a string. The input string is given as an array of characters s.

You must do this by modifying the input array in-place with O(1) extra memory.

Example 1:

Input: s = ["h","e","l","l","o"]
Output: ["o","l","l","e","h"]

Example 2:

Input: s = ["H","a","n","n","a","h"]
Output: ["h","a","n","n","a","H"]

Constraints:

Hints open one at a time

Hint 1
The entire logic for reversing a string is based on using the opposite directional two-pointer approach!
9:03
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def reverseString(self, s: List[str]) -> None:
3 """
4 Do not return anything, modify s in-place instead.
5 """
6
Starter codePython 3Spaces: 4
Examples
Input
["h","e","l","l","o"]
Input
["H","a","n","n","a","h"]
Your code is saved on this device.Solution