Skip to content
CodeShare
All problems

Reverse String

Reverse an array of characters in place.

EasyStringsTwo pointers

The string is given as an array of characters s. Reverse it in place, using only O(1) extra memory. The tests check s after your function finishes.

Examples

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

  • 1 <= s.length <= 10^5
  • Each s[i] is a printable ASCII character.