题解链接如下 https://leetcode-cn.com/problems/longest-substring-of-all-vowels-in-order/solution/zai-bian-li-guo-cheng-zhong-you-tui-hua-h1q0s/ 思路分析 分别对'a'、'e'、'i'、'o'、'u'进行处理即可 class Solution { public: int longestBeautifulSubstring(string word) { char temp; //保存上一个元素的字符 int len=0; map<char,int> mp; auto f=[&](){ //全部退化掉 mp['e']=0;mp['i']=0;mp['o']=0;mp['u']=0;mp['a']=0; }; for(auto &t:word){ switch(t){ case 'a': if(mp['e']>=1||mp['i']>=1||mp['o']>=1||mp['u']>=1) f(); mp['a']++; break; case 'e': if(mp['a']>=1&&mp['i']==0&&mp['o']==0&&mp['u']==0) mp['e']++; else f(); break; case 'i': if(mp['a']>=1&&mp['e']>=1&&mp['o']==0&&mp['u']==0) mp['i']++; else f(); break; case 'o': if(mp['a']>=1&&mp['e']>=1&&mp['i']>=1&&mp['u']==0) mp['o']++; else f(); break; case 'u': if(mp['a']>=1&&mp['e']>=1&&mp['i']>=1&&mp['o']>0) mp['u']++; else f(); int t=mp['a']+mp['e']+mp['i']+mp['o']+mp['u']; if(t>len) len=t; break; } } return len; } };