Advertisement
jibha

Untitled

Jan 21st, 2022
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. class Solution {
  2. public:
  3.  
  4. bool isVowel(char c){
  5. if(c=='u'||c=='U'){
  6. return true;
  7. }else if(c=='o'||c=='O'){
  8. return true;
  9. }else if(c=='a'||c=='A'){
  10. return true;
  11. }else if(c=='e'||c=='E'){
  12. return true;
  13. }else if(c=='i'||c=='I'){
  14. return true;
  15. }else{
  16. return false;
  17. }
  18. }
  19.  
  20. string reverseVowels(string s) {
  21. vector<char> vowel;
  22.  
  23. for(char c:s){
  24. if(isVowel(c)){
  25. vowel.push_back(c);
  26. }
  27. }
  28. reverse(vowel.begin(),vowel.end());
  29. string ans;
  30. int ind=0;
  31.  
  32. for(char c:s){
  33. if(isVowel(c)){
  34. ans=ans+vowel[ind];
  35. ind++;
  36. }else{
  37. ans=ans+c;
  38. }
  39. }
  40.  
  41. return ans;
  42. }
  43. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement