SHARE
TWEET

Untitled

a guest Jan 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution(object):
  2.     mem={}
  3.     for i in range(0,27):
  4.         if i<=10 or i%10==0:
  5.             mem[str(i)]=1
  6.         else:
  7.             mem[str(i)]=2
  8.     mem['0']=0
  9.     mem['00']=0
  10.     def numDecodings(self, s):
  11.         """
  12.        :type s: str
  13.        :rtype: int
  14.        """
  15.         if '00' in s or s[0]=='0':
  16.             return 0
  17.            
  18.         if s in self.mem:
  19.             return self.mem[s]
  20.         count=0
  21.         c1=0
  22.         c1=self.numDecodings(s[1:])
  23.         c2=0
  24.         self.mem[s[1:]]=c1
  25.         if int(s[:2])<=26:
  26.             c2=self.numDecodings(s[2:])
  27.             self.mem[s[2:]]=c2
  28.         count+=c1+c2
  29.         #print(s,count)
  30.         return count
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top