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".
Note:
The vowels does not include the letter "y".
解题思路:将元音字母调换位置
class Solution {
public:
string reverseVowels(string s) {
int dist[256]={0};
dist['a']=1;dist['A']=1;
dist['e']=1;dist['E']=1;
dist['i']=1;dist['I']=1;
dist['o']=1;dist['O']=1;
dist['u']=1;dist['U']=1;
int begin=0;
int end=(int)s.size()-1;
while(begin<end){
while(begin<end && dist[s[begin]]==0)begin++;
while(begin<end && dist[s[end]]==0)end--;
swap(s[begin],s[end]);
begin++;
end--;
}
return s;
}
};