feat: added alternative python solutions.
This commit is contained in:
16
decode-ways/src/alternative-ac2.py
Normal file
16
decode-ways/src/alternative-ac2.py
Normal file
@@ -0,0 +1,16 @@
|
||||
n = int(input())
|
||||
s = input().strip()
|
||||
|
||||
dp = [0] * (n + 1)
|
||||
dp[0] = 1
|
||||
|
||||
for i in range(1, n + 1):
|
||||
if s[i - 1] != '0':
|
||||
dp[i] += dp[i - 1]
|
||||
|
||||
if i > 1:
|
||||
two_digit = int(s[i - 2:i])
|
||||
if 10 <= two_digit <= 26:
|
||||
dp[i] += dp[i - 2]
|
||||
|
||||
print(dp[n])
|
||||
Reference in New Issue
Block a user