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) {
vector<char>ss;
int *record=new int[1000000];
char *record_temp=new char[1000000];
int count=0;//num_counter
for(int i=0;i<s.length();i++){
if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'){
ss.push_back(s[i]);
*(record+i)=1;
}
else{
*(record_temp+i)=s[i];
}
}
reverse(ss.begin(),ss.end());
for(int i=0;i<s.length();i++){
if(*(record+i)==1){
*(record_temp+i)=ss[count];
count++;
}
}
return record_temp;
}
};