#
#
# @param s string字符串
# @return int整型
#
class Solution:
def numDecodings(self , s ):
a=1
b=1
dp=1
if s == '' or s[0] == '0':
return 0
else:
for i in range(1,len(s)):
if int(s[i]) == 0 and(int(s[i-1] )> 2 or int(s[i-1]) ==0):
return 0
elif int(s[i]) != 0 and (int(s[i-1]) == 1 or (int(s[i-1])==2 and int(s[i]) <7) ) :
dp = a+b
else:
dp= b
a , b = b , dp
return dp

京公网安备 11010502036488号