Skip to content

Commit e98b8ae

Browse files
Merge pull request #41 from akshaysoni10/LeetCode-Solution
Reverse Vowels Of String solution updated
2 parents 73b7173 + 9dc4083 commit e98b8ae

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Reverse_Vowels_Of_String.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public:
3+
bool isVowel(char c){
4+
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
5+
}
6+
7+
string reverseVowels(string s) {
8+
int n = s.length();
9+
int st = 0;
10+
int e = n-1;
11+
while(st<e){
12+
if(!isVowel(s[st])){
13+
st++;
14+
continue;
15+
}
16+
if(!isVowel(s[e])){
17+
e--;
18+
continue;
19+
}
20+
swap(s[st], s[e]);
21+
st++;
22+
e--;
23+
}
24+
return s;
25+
}
26+
};

0 commit comments

Comments
 (0)