leetcode345 C++ 12ms 反转字符串中的元音
class Solution {
public:
string reverseVowels(string s) {
set<char> vow = {'a', 'e', 'o', 'i', 'u', 'A', 'E', 'I', 'O', 'U'};
auto left = s.begin();
auto right = s.end() - 1;
while(left < right){
while(!vow.count(*left) && left<right ){
left++;
}
while(!vow.count(*right) && left<right){
right--;
}
auto temp = *right;
*right = *left;
*left = temp;
left++;
right--;
}
return s;
}
};