Description

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.

Examples

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

The string 'hello' reversed is 'olleh'.

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

The string 'Hannah' reversed is 'hannaH'.

Input:s = ["1","2","3","4","5","6","7"]
Output:["7","6","5","4","3","2","1"]
Explanation:

The string '1234567' reversed is '7654321'. This example demonstrates reversing a string with an odd number of characters using numeric digits.

Constraints

  • 1 ≤ s.length ≤ 10⁵
  • s[i] is a printable ascii character.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!