вот если переименовать, чтобы глядя на них было ясно что означают, без погружения в контекст задачи, будет лучше :-)
Ну вот мое, но без объяснений все равно нихрена не понятно:
class Solution:
def numDecodings(self, s: str) -> int:
ways = 1
pairs, single = 0, 1
for i in range(len(s)):
if s[i] == '0' and (not i or s[i - 1] not in {'1', '2'}):
return 0
elif i != len(s) - 1 and int(s[i] + s[i + 1]) < 27 and \
s[i + 1] != '0' and (i == len(s) - 2 or s[i + 2] != '0'):
pairs, single = single, single + pairs
else:
ways *= pairs + single
pairs, single = 0, 1
return ways * (pairs + single)