Last active
December 26, 2015 23:49
-
-
Save darkowlzz/7233565 to your computer and use it in GitHub Desktop.
Longest Seq
This file contains hidden or 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 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