◻️345. Reverse Vowels of a String (easy)
Input: s = "hello"
Output: "holle"Input: s = "leetcode"
Output: "leotcede"Solutions
Normal
// Solution taken from leetcode.
class Solution {
public:
string reverseVowels(string s) {
int i=0;
int j=s.length()-1;
while(i < j){
while(i < j && !isVowel(s[i])){
i++;
}
while(i < j && !isVowel(s[j])){
j--;
}
if(i<j){
swap(s[i], s[j]);
i++;
j--;
}
}
return s;
}
private:
bool isVowel(char c){
c = tolower(c);
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
};Own Solution
Last updated