Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 543 Bytes

91.md

File metadata and controls

34 lines (23 loc) · 543 Bytes

91 Decode Ways

Description

link


Solution

  • w : current answer of decode ways

  • v : previous answer of decode ways

  • pre : previous character


Code

Complexity T : O(n)

class Solution:
    def numDecodings(self, s):
        """
        :type s: str
        :rtype: int
        """
        v, w, pre = 0, int(len(s) > 0), ''
        for c in s:
            v, w, pre = w, (c > '0') * w + (9 < int(pre + c) < 27) * v, c
        return w