Search⌘ K
AI Features

Solution: Reverse Vowels of a String

Understand how to apply the two pointers pattern to reverse vowels in a string without affecting other characters. This lesson guides you through pointer manipulation, vowel detection, and in-place swapping, helping you solve similar string manipulation problems with O(n) time complexity and O(n) space complexity.

Statement

Given a string s, reverse only the vowels in the string and return the resulting string.

The vowels are ‘a’‘e’‘i’‘o’, and ‘u’, and they can appear in both lowercase and uppercase, potentially more than once.

Constraints:

  • 11 \leq s.length 3×105 ...