1839所有元音按顺序排布的最长子字符串
class Solution {
public:
int longestBeautifulSubstring(string word) {
int ans = 0;
string str;
set<char> s;
for (auto words : word) {
if (str.empty() || words >= str.back()) {
str.push_back(words);
s.insert(words);
}
else {
if (str.length() > ans && s.size() == 5) ans = str.length();
str.clear();
s.clear();
str.push_back(words);
s.insert(words);
}
}
if (str.length() > ans && s.size() == 5) ans = str.length();
return ans;
}
};
查看8道真题和解析