Leetcode 345. Reverse Vowels of a String (Easy) (cpp)
Tag: Two Pointers, String
Difficulty: Easy
class Solution {
public:
string reverseVowels(string s) {
string vowels = "aeiouAEIOU";
int left = 0, right = s.length() - 1;
while (left < right) {
while (vowels.find(s[left]) == -1 && left < right) {
left++;
}
while (vowels.find(s[right]) == -1 && left < right) {
right--;
}
swap(s[right--], s[left++]);
}
return s;
}
};