-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReverse-Vowel.cpp
More file actions
34 lines (27 loc) · 849 Bytes
/
Copy pathReverse-Vowel.cpp
File metadata and controls
34 lines (27 loc) · 849 Bytes
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
{
public:
string reverseVowels(string s)
{
int i = 0;
int j = s.size()-1;
while(i<j)
{
bool flag1 = false, flag2 = false;
if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u' || s[i]=='A' || s[i]=='E' || s[i]=='I' || s[i]=='O' || s[i]=='U')
flag1 = true;
if(s[j]=='a' || s[j]=='e' || s[j]=='i' || s[j]=='o' || s[j]=='u' || s[j]=='A' || s[j]=='E' || s[j]=='I' || s[j]=='O' || s[j]=='U')
flag2 = true;
if(flag1 && flag2)
{
swap(s[i],s[j]);
i++;j--;
}
if(!flag1)
i++;
if(!flag2)
j--;
}
return s;
}
};