Python solution in 4 lines


  • 0
    H
    class Solution(object):
        def numDecodings(self, s):
            dp = [int(s[0] != '0')] if s else [0]
            for i in xrange(1, len(s)):
                dp.append(dp[i-1] * (s[i] != '0') + dp[i-2] * (10 <= int(s[i-1:i+1]) <= 26))
            return dp[-1]

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.