Skip to content

Instantly share code, notes, and snippets.

@darkowlzz
Last active December 26, 2015 23:49
Show Gist options
  • Select an option

  • Save darkowlzz/7233565 to your computer and use it in GitHub Desktop.

Select an option

Save darkowlzz/7233565 to your computer and use it in GitHub Desktop.
Longest Seq
def findSeq(str):
# A list to store the words.
seq = []
# Create words from the given string and
# store in seq.
word = str[0]
for i in range(len(str)-1):
current = ord(str[i])
next = ord(str[i+1])
if current <= next:
word += str[i+1]
else:
seq.append(word)
word = str[i+1]
seq.append(word)
# Find the longest word and return it.
longest = seq[0]
for i in range(len(seq)-1):
if len(seq[i]) < len(seq[i+1]):
longest = seq[i+1]
return longest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment