Simple C++ Solution


  • 0
    F
    
        bool is_vowel(char ch) {
            ch = tolower(ch);
            if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
                 return true;
            else return false;
        }
        string reverseVowels(string s) {
            int left = 0, right = (int)s.size() - 1;
            while (left < right) {
                while (left < right && !is_vowel(s[left])) ++left;
                while (right > left && !is_vowel(s[right])) --right;
                swap(s[left], s[right]);
                left++; --right;
            }
            return s;
        }
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.