Python实现【最长的指定瑕疵度的元音子串】

B站影视 港台电影 2025-05-25 14:15 3

摘要:def longest_vowel_substring: import sys flaw = int(sys.stdin.readline) s = sys.stdin.readline.strip vowels = {'a', 'e', 'i', 'o',

def longest_vowel_substring: import sys flaw = int(sys.stdin.readline) s = sys.stdin.readline.strip vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'} n = len(s) vowel_indices = for i, char in enumerate(s): if char in vowels: vowel_indices.append(i) max_len = 0 left = 0 for right in range(len(vowel_indices)): while left flaw: left += 1 current_flaw = vowel_indices[right] - vowel_indices[left] + 1 - (right - left + 1) if current_flaw == flaw: max_len = max(max_len, vowel_indices[right] - vowel_indices[left] + 1) print(max_len)longest_vowel_substring

来源:立辉教育

相关推荐