-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
34 lines (31 loc) · 928 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution {
unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u',
'A', 'E', 'I', 'O', 'U'};
public:
string reverseVowels(string s) {
for (int l = 0, r = s.size() - 1; l < r;) {
if (vowels.count(s[l]) == 0) {
++l;
} else if (vowels.count(s[r]) == 0) {
--r;
} else {
swap(s[l++], s[r--]);
}
}
return s;
}
};
class Solution {
const unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u',
'A', 'E', 'I', 'O', 'U'};
public:
string reverseVowels(string s) {
int l = 0, r = s.size() - 1;
while (l < r) {
while (l < r && vowels.count(s[l]) == 0) ++l;
while (l < r && vowels.count(s[r]) == 0) --r;
swap(s[l++], s[r--]);
}
return s;
}
};