246. Reverse Vowels of a String

MediumStringString

Given a string s, reverse only the vowels (a, e, i, o, u in both cases) and return the resulting string. All other characters stay in place.

Input: A quoted string s.

Output: Quoted string — vowels reversed.

Examples

Example 1
Input: "hello"
Output: "holle"
Explanation: e and o swapped.
Example 2
Input: "leetcode"
Output: "leotcede"
Explanation: Vowels reversed in place.
Example 3
Input: "aA"
Output: "Aa"
Explanation: Both are vowels.

Constraints

Asked by

DeloitteOracleBloombergGoogleMicrosoftAmazon
Solve this problem in the editor →