share my C++ solution


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

Log in to reply
 

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