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

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
7
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务