leetcode 1839. Longest Substring Of All Vowels in Order
Problem: 1839. 所有元音按顺序排布的最长子字符串去掉连续重复的字符并记录每个连续字符的起始索引的查找aeiou用后者索引减去前者索引。索引都是开始的所以要用ind 5Codeclass Solution { public: int longestBeautifulSubstring(string word) { string tg; tg word[0]; word 00; int n word.size(); vectorint arr{0}; for(int i 1; i n; i) { if(word[i] ! word[i-1]) { tg word[i]; arr.push_back(i); } } int ind tg.find(aeiou), mx 0; while(ind ! string::npos) { mx max(mx, arr[ind 5] - arr[ind]); ind tg.find(aeiou, ind 4); } return mx; } };
上一篇/下一篇内容由系统自动关联
返回资讯列表 →