-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0345. Reverse Vowels of a String.cpp
More file actions
45 lines (40 loc) · 1.04 KB
/
0345. Reverse Vowels of a String.cpp
File metadata and controls
45 lines (40 loc) · 1.04 KB
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
35
36
37
38
39
40
41
42
43
44
45
class Solution {
public:
string reverseVowels(string s) {
if(s.length() <= 1){
return s;
}
int two = s.length()-1;
int one = 0;
bool bCheck=true;
char aux;
while(bCheck){
if(isVowel(s[one]) && isVowel(s[two])){
aux = s[one];
s[one] = s[two];
s[two] = aux;
one++;
two--;
}
else if(!isVowel(s[one])){
one++;
}
else if(!isVowel(s[two])){
two--;
}
if(one >= two){
bCheck=false;
}
}
return s;
}
bool isVowel(char c){
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
return true;
}
if(c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'){
return true;
}
return false;
}
};