My clear cpp solution


  • 2
    C
    class Solution {
    public:
        bool isVowel(char c)
        {
            return c=='a' || c=='e' || c=='i' || c=='o' || c=='u'
                || c=='A' || c=='E' || c=='I' || c=='O' || c=='U';
        }
    
        string reverseVowels(string s) 
        {
            int i=0, j=s.size()-1;
            while(1)
            {
                while(i < j && !isVowel(s[i]))
                    i++;
                while(i < j && !isVowel(s[j]))
                    j--;
                
                if(i >= j) break;
                
                std::swap(s[i++], s[j--]);
            }
            
            return s;
        }
    };

Log in to reply
 

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