题目链接
https://leetcode.com/problems/reverse-vowels-of-a-string/
题目原文
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Given s = “hello”, return “holle”.Example 2:
Given s = “leetcode”, return “leotcede”.
题目翻译
写一个函数,输入一个字符串,仅将其中的元音字母逆序。
例子1:输入”hello”,输出”holle”;例子2:输入”leetcode”,输出”leotcede”。
思路方法
首先,要知道哪些是元音字母:a, o, e, i, u, A, O, E, I, U.
思路一
一遍扫描所有字符,记录所有元音字母和它们出现的位置到一个数组中;再扫描这个数组,将元音字母逆序填回原来的字符串相应位置。
代码
class