From 558a84506b18d889337e890af7d58857d9f8cc9b Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Mon, 25 Dec 2023 12:28:11 -0500 Subject: 91 --- 91/main.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 91/main.py (limited to '91') 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() -- cgit v1.2.3