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) { int l=0,r=s.length()-1; set<char>st; st.insert('a'); st.insert('e'); st.insert('i'); st.insert('o'); st.insert('u'); st.insert('A'); st.insert('E'); st.insert('I'); st.insert('O'); st.insert('U'); while(l<r){ if(st.count(s[l])&&st.count(s[r])){ swap(s[l],s[r]); l++; r--; } else if(st.count(s[l])){ r--; } else if(st.count(s[r])){ l++; } else{ l++; r--; } } return s; } };