leetcode 345. Reverse Vowels of a String

    string reverseVowels(string s) {
        for (int i = 0, j = s.size() - 1; i < j;) {
            bool l = isVowels(s[i]);
            bool r = isVowels(s[j]);
            if (l && r)
                swap(s[i++], s[j--]);
            else {
                if (!l)
                    i++;
                if (!r)
                    j--;
            }
        }
        return move(s);
    }
    
    bool isVowels(const char& c) {
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
               c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';
    }

 

posted on 2018-02-08 15:45  willaty  阅读(101)  评论(0编辑  收藏  举报

导航