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".
class Solution {
public:
string reverseVowels(string s) {
set<char> str{'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O','U'};
int i =0, j = s.size() - 1;
while (i <= j) {
if (str.count(s[i]) != 0 && str.count(s[j]) != 0) {
swap(s[i], s[j]);
++i;
--j;
}
if (str.count(s[j]) == 0)
--j;
if (str.count(s[i]) == 0)
++i;
}
return s;
}
};