knakul853

Untitled

Jun 20th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. /**
  2. knakul853
  3. **/
  4. class Solution {
  5. public:
  6.     string reverseVowels(string s) {
  7.        
  8.         int i=0;
  9.         int j = (int)s.size()-1;
  10.         string vowels="aeiouAEIOU";
  11.        
  12.         while(i <j )
  13.         {
  14.             while(i < j &&  vowels.find(s[i]) == string::npos){
  15.                 i++;
  16.             }
  17.             while(i < j && vowels.find(s[j])== string::npos) j--;
  18.            
  19.             if(i < j )
  20.             {
  21.                 swap(s[i], s[j]);
  22.             }
  23.                    
  24.             i++;j--;
  25.         }
  26.        
  27.         return s;
  28.     }
  29. };
Add Comment
Please, Sign In to add comment