diff options
author | terminaldweller <devi@terminaldweller.com> | 2023-12-25 17:28:11 +0000 |
---|---|---|
committer | terminaldweller <devi@terminaldweller.com> | 2023-12-25 17:28:11 +0000 |
commit | 558a84506b18d889337e890af7d58857d9f8cc9b (patch) | |
tree | b469f7023131b656eacc23cd4f50cea3a80ece1d | |
parent | 1758 (diff) | |
download | leetcode-558a84506b18d889337e890af7d58857d9f8cc9b.tar.gz leetcode-558a84506b18d889337e890af7d58857d9f8cc9b.zip |
91
Diffstat (limited to '')
-rwxr-xr-x | 91/main.py | 31 |
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() |