QUESTION->
CODE–>
Not Passing all testcases help
Reverse vowels of strings
bro i got it it is two pointers approach i made mistake in control flow statements
class Solution {
bool vowel(char a,char b){
if((a=='a' or a=='A' or a=='e' or a=='E' or a=='i' or a=='I' or a=='O' or a=='o' or a=='u' or a=='U') and (b=='a' or b=='A' or b=='e' or b=='E' or b=='i' or b=='I' or b=='O' or b=='o' or b=='u' or b=='U')){
return true;
}
return false;
}
bool vowel1(char a){
if((a=='a' or a=='A' or a=='e' or a=='E' or a=='i' or a=='I' or a=='O' or a=='o' or a=='u' or a=='U') ){
return true;
}
return false;
}
public:
string reverseVowels(string S) {
int i=0;
int j=S.length()-1;
while(i<j){
if(vowel(S[i],S[j])){
swap(S[i++],S[j--]);
}
else{
if(vowel1(S[i])){
j--;
}
else if(vowel1(S[j])){
i++;
}
else if(vowel1(S[i])==false and vowel1(S[j])==false){
i++;j--;
}
}
}
return S;
}
};
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.