C++ 16ms solution, like partition in quicksort()


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