题目:给定一个字符串,寻找其中最长的连续元音子串,返回该子串长度
思路,将原来的字符串中非元音字母的用空格代替,并以空格切分,再计算长度
def longest_vowel_length(in_str):
for i in in_str:
if i not in vowel:
in_str = in_str.replace(i, ‘ ‘)
new_str_arr = in_str.split(‘ ‘)
new_str_arr_len = []
for i in new_str_arr:
new_str_arr_len.append(len(i))
return sorted(new_str_arr_len, reverse=True)
if __name__ == ‘__main__‘:
test_string = ‘asdbusisaeivassssusufgh‘
in_str = test_string.strip()
vowel = ‘aeiouAEIOU‘
new_str = longest_vowel_length(in_str)
print(new_str[0])
原文:https://www.cnblogs.com/GumpYan/p/12994540.html