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)
{
set<char> s1;
s1.insert('a');
s1.insert('e');
s1.insert('i');
s1.insert('o');
s1.insert('u');
s1.insert('A');
s1.insert('E');
s1.insert('I');
s1.insert('O');
s1.insert('U');
stack<char> s2;
vector<int> id;
for(int i=0; i<s.size(); i++)
{
if(s1.count(s[i]))
{
s2.push(s[i]);
id.push_back(i);
}
}
for(int i=0; i<id.size(); i++)
{
s[id[i]] = s2.top();
s2.pop();
}
return s;
}
};