leetcode345 C++ 12ms 反转字符串中的元音

class Solution {
public:
    string reverseVowels(string s) {
        set<char> vow = {'a', 'e', 'o', 'i', 'u', 'A', 'E', 'I', 'O', 'U'};
        auto left = s.begin();
        auto right = s.end() - 1;
        while(left < right){
            while(!vow.count(*left) && left<right ){
                left++;
            }
            while(!vow.count(*right) && left<right){
                right--;
            }
            auto temp = *right;
            *right = *left;
            *left = temp;
            left++;
            right--;
        }
        return s;
    }
};

posted @ 2018-07-26 17:04  一条图图犬  阅读(145)  评论(0编辑  收藏  举报