1839. Longest Substring Of All Vowels in Order (Medium) - TengnanYao/daily_leetcode GitHub Wiki

class Solution:
    def longestBeautifulSubstring(self, word: str) -> int:
        result, cur, s = 0, 0, set()
        word = "u" + word + "a"
        for i in range(1, len(word)):
            cur += 1
            if word[i] < word[i - 1]:
                if len(s) == 5:
                    result = max(cur, result)
                cur, s = 0, set()
            s.add(word[i])
        return result