Reverse vowels of a String | LeetCode problem 345

preview_player
Показать описание
Reverse vowels of a String
Leetcode problem number 345
Solution in JAVA

JAVA interview programming playlist:

#java #interviewquestions #leetcode
Рекомендации по теме
Комментарии
Автор

class Solution {
public:
bool isVowel(char ch){
ch = tolower(ch);
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
return true;
return false;
}
string reverseVowels(string ch) {
//using two pointers start and end;
int start=0, end=ch.size()-1;
while(start<=end){
bool isLowVowel = isVowel(ch[start]);
bool isHighVowel = isVowel(ch[end]);

if(isLowVowel && isHighVowel){
// now both the pointers must be on vowels
char temp = ch[start];
ch[start] = ch[end]; /// SWAP
ch[end] = temp;
start++; end--;
}
if(!isLowVowel){
start++;
}
if(!isHighVowel){
end--;
}
}
return ch;
}
};

siddheshb.kukade
Автор

Great explanation👍👍
Plz upload more such problem

rojidansari
Автор

Thanks for the explanation, the concept is clear. Although the time complexity will be too high for this, leet code doesn't accept this solution. Needs optimization.

khushiprasad
Автор

Your solution will not be accepted in Leetcode

smasifhossain
Автор

Why are you not uploading leetcode problem

raadali