Skip to content

Reverse String

EasyTwo Pointers
Decode it first. Clues, constraints, pattern and plan before any code.

You are given a string as a list of characters s. Reverse it in place: change the list itself and return nothing. Use only O(1) extra memory.

s = ["h", "e", "l", "l", "o"]        →  s becomes ["o", "l", "l", "e", "h"]
s = ["H", "a", "n", "n", "a", "h"]   →  s becomes ["h", "a", "n", "n", "a", "H"]

Constraints

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