Skip to content

Reverse Vowels of a String

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

Given a string s, reverse only the vowels and return the result. Every other character stays where it is. The vowels are a, e, i, o, u, in lowercase and uppercase.

s = "IceCreAm"     →  "AceCreIm"
s = "leetcode"     →  "leotcede"
s = "hello world"  →  "hollo werld"

Constraints

  • 1 <= s.length <= 3 * 10^5
  • s consists of printable ASCII characters.