Created
December 20, 2016 18:34
-
-
Save miqueiaspenha/91e6383605deaf124f68f7865a2d7d42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def obter_mais_longa_substring(s): | |
''' | |
s: string que será passada | |
Essa função retorna a mais longa substring de texto em ordem alfabética. | |
''' | |
letra_anterior = '' | |
conjunto = [] | |
conjuntos = [] | |
for letra_atual in s: | |
if(letra_atual >= letra_anterior): | |
conjunto.append(letra_atual) | |
else : | |
texto = ''.join(conjunto) | |
conjuntos.append(texto) | |
conjunto[:] = [] | |
conjunto.append(letra_atual) | |
letra_anterior = letra_atual | |
substring = '' | |
for i in conjuntos: | |
if(len(i) > len(substring)): | |
substring = i | |
return substring | |
print(obter_mais_longa_substring('azcbobobegghakl')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment