Problem
Write a function that takes a string as input and reverse only the vowels of a string.
1
2
3
4
5
6
7
8Example 1:
Input: "hello"
Output: "holle"
Example 2:
Input: "leetcode"
Output: "leotcede"
Note: The vowels does not include the letter “y”.
Solution
Analysis
翻转字符串中的元音字母. 首先,我们需要记录元音字母都有哪些, 然后双指针遍历字符串,判断当前字符是否属于元音字母,找到之后交换位置,继续遍历.
Code
1 | class Solution { |