345. 反转字符串中的元音字母

 1 class Solution 
 2 {
 3     unordered_set<char> hash = {'a','e','i','o','u','A','E','I','O','U'};
 4 public:
 5     string reverseVowels(string s) 
 6     {
 7         int n = s.size();
 8         int begin = 0,end = n - 1;
 9         while(begin < end)
10         {
11             while(begin < end && hash.count(s[begin]) == 0) begin ++;
12             while(begin < end && hash.count(s[end]) == 0) end --;
13             swap(s[begin ++],s[end --]);
14         }
15         return s;
16     }
17 };

 

posted @ 2020-04-22 19:08  Jinxiaobo0509  阅读(122)  评论(0)    收藏  举报