aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x91/main.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/91/main.py b/91/main.py
new file mode 100755
index 0000000..3099c7b
--- /dev/null
+++ b/91/main.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+
+class Solution:
+ def numDecodings(self, s: str) -> int:
+ if s[0] == "0":
+ return 0
+
+ dp = [0] * (len(s) + 1)
+ dp[0], dp[1] = 1, 1
+
+ for i in range(2, len(s) + 1):
+ print(s[i - 1 : i])
+ if 0 < int(s[i - 1 : i]) <= 9:
+ dp[i] += dp[i - 1]
+ print(s[i - 2 : i])
+ if 10 <= int(s[i - 2 : i]) <= 26:
+ dp[i] += dp[i - 2]
+
+ return dp[-1]
+
+
+def main():
+ solution = Solution()
+ print(solution.numDecodings("12"))
+ print(solution.numDecodings("226"))
+ print(solution.numDecodings("06"))
+
+
+if __name__ == "__main__":
+ main()