码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-04-22 20:18:02      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:size   ret   solution   while   pre   col   public   反转   turn   

 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 };

 

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

标签:size   ret   solution   while   pre   col   public   反转   turn   

原文地址:https://www.cnblogs.com/yuhong1103/p/12755269.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!