Skip to main content
LeetCode 345, Easy. Topics: Two Pointers, String. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 18 parametrized pytest cases, and a playground notebook:

Problem

Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.

Examples

Explanation: The vowels in s are ['I', 'e', 'e', 'A']. On reversing the vowels, s becomes “AceCreIm”.

Constraints

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

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026