Skip to content

Instantly share code, notes, and snippets.

@phondanai
Created January 19, 2017 07:13
Show Gist options
  • Save phondanai/0c73d37c01310bfe08b6d6bc4ed80dfd to your computer and use it in GitHub Desktop.
Save phondanai/0c73d37c01310bfe08b6d6bc4ed80dfd to your computer and use it in GitHub Desktop.
Stupid solution of print longest sequence of character from string s
s = 'azcbobobegghakl'
result = ''
tmp = ''
for i in range(len(s)-1):
if s[i] <= s[i+1]:
tmp += s[i]
if i == len(s) - 2:
tmp += s[i+1]
if len(tmp) > len(result):
result = tmp
else:
tmp += s[i]
if len(tmp) > len(result):
result = tmp
tmp = ''
print("Longest substring in alphabetical order is: " + result)
# Longest substring in alphabetical order is: beggh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment