-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy path2104-total-characters-in-string-after-transformations-i.py
More file actions
65 lines (57 loc) · 1.32 KB
/
2104-total-characters-in-string-after-transformations-i.py
File metadata and controls
65 lines (57 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from functools import lru_cache
class Solution:
def lengthAfterTransformations(self, s: str, t: int) -> int:
d = {
'a': 0,
'b': 1,
'c': 2,
'd': 3,
'e': 4,
'f': 5,
'g': 6,
'h': 7,
'i': 8,
'j': 9,
'k': 10,
'l': 11,
'm': 12,
'n': 13,
'o': 14,
'p': 15,
'q': 16,
'r': 17,
's': 18,
't': 19,
'u': 20,
'v': 21,
'w': 22,
'x': 23,
'y': 24,
'z': 25
}
MOD = 10**9 + 7
ans = 0
memo = {}
def count(c):
if c < 26:
return 1
if c in memo:
return memo[c]
temp = count(c-26) + count(c-25)
memo[c] = temp
return temp
for l in s:
ans += count(d[l]+t)
return ans % MOD
s = "abcyy"
t = 26
print(Solution().lengthAfterTransformations(s, t))
s = "azbk"
t = 1
print(Solution().lengthAfterTransformations(s, t))
s = "jqktcurgdvlibczdsvnsg"
t = 5
print(Solution().lengthAfterTransformations(s, t))
s = "jqktcurgdvlibczdsvnsg"
t = 480
print(Solution().lengthAfterTransformations(s, t))