Reverse Vowels of a String
Problem statement
Given a string s, reverse only its vowel characters and return the resulting string.
The vowels are a, e, i, o, and u, in either lowercase or uppercase. Preserve every vowel's original character and case while reversing their order. Every non-vowel character remains at its original index.
The string may be large, so avoid repeated string rebuilding that takes quadratic time.
Function
reverseVowels(s: String) → StringExamples
Example 1
s = "hello"return = "holle"The vowels are e and o. Reversing them produces holle.
Example 2
s = "leetcode"return = "leotcede"The vowel sequence e, e, o, e becomes e, o, e, e; consonants keep their positions.
Example 3
s = "aA"return = "Aa"Uppercase and lowercase vowels both participate, and their original cases move with the characters.
Constraints
0 <= s.length <= 10^6.scontains printable ASCII characters.