class Solution {
public:
string reverseVowels(string s) {
string vowels = "aeiouAEIOU";
int end = s.size()-1;
int start = 0;
while(start < end){
while(vowels.find(s[start]) == string::npos)
start++;
while(vowels.find(s[end]) == string::npos)
end--;
if(start <= end){
swap(s[start],s[end]);
start++,end--;
}
}
return s;
}
};
LeetCode 345. Reverse Vowels of a String
最新推荐文章于 2023-12-07 16:56:30 发布