题目链接:https://leetcode-cn.com/problems/reverse-vowels-of-a-string/
双指针法,一个从前向后,一个从后向前,遍历条件和交换条件都是i<j,一旦i=j就退出
class Solution {
public:
string reverseVowels(string s) {
const string vowels = "aeiouAEIOU";
int i = 0, j = s.size() - 1;
while(i<j){
while((vowels.find(s[i])==-1) && i<j) i++;
while((vowels.find(s[j])==-1) && i<j) j--;
if(i<j) swap(s[i++],s[j--]);
}
return s;
}
};