Skip to content

Instantly share code, notes, and snippets.

@lttzzlll
Created May 21, 2018 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lttzzlll/2230b95800e0e9d126171215d5b2b166 to your computer and use it in GitHub Desktop.
Save lttzzlll/2230b95800e0e9d126171215d5b2b166 to your computer and use it in GitHub Desktop.
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