Created
May 21, 2018 06:26
-
-
Save lttzzlll/2230b95800e0e9d126171215d5b2b166 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 max_count(string): | |
"""count max length of no-26 length | |
>>> max_count('') | |
0 | |
>>> max_count('1') | |
1 | |
>>> max_count('12') | |
2 | |
>>> max_count('123') | |
3 | |
>>> max_count('1234') | |
3 | |
>>> max_count('12341') | |
3 | |
>>> max_count('12321') | |
4 | |
Arguments: | |
string {[str]} -- [input string] | |
Returns: | |
[int] -- [max count] | |
""" | |
if not string: return 0 | |
dp = [0] * len(string) | |
for idx, ele in enumerate(string): | |
if idx == 0: | |
dp[idx] = 1 | |
else: | |
if int(string[idx-1: idx+1]) <= 26: | |
dp[idx] = dp[idx-1] + 1 | |
else: | |
dp[idx] = dp[idx-1] | |
return dp[-1] | |
if __name__ == '__main__': | |
import doctest | |
doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment