91. Decode Ways

```
class Solution(object):
def numDecodings(self, s):
"""
:type s: str
:rtype: int
"""

    if s==''or s[0]=='0':
        return 0
        
    d=[1 for i in xrange(len(s)+1)]
    
    for i in xrange(2,len(s)+1):
        if (s[i-2]!='0' and s[i-2:i]>'0' and s[i-2:i]<'27'and s[i-1]!='0'):
            d[i]=d[i-1]+d[i-2]
        elif(s[i-1]=='0'):
            if (s[i-2]!='0' and s[i-2:i]>'0' and s[i-2:i]<'27'):
                d[i]=d[i-2]
                #two consecutive zeros
            else:return 0
        else: d[i]=d[i-1]
    return d[len(s)]

```

你可能感兴趣的:(91. Decode Ways)