Skip to content

Commit d901005

Browse files
authored
Create Day-8_Shifting_Letters.py
1 parent 031ea61 commit d901005

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Time: O(N) and Space: O(1)
2+
3+
class Solution:
4+
def shiftingLetters(self, s: str, shifts: List[int]) -> str:
5+
a = ord('a')
6+
d = {chr(c): c - a for c in range(a, a+26)}
7+
rd = {c - a: chr(c) for c in range(a, a+26)}
8+
for i in range(len(shifts)-2,-1,-1):
9+
shifts[i] += shifts[i+1]
10+
11+
ans = ''
12+
for i in range(len(s)):
13+
ans += rd[(d[(s[i])] + shifts[i]) % 26]
14+
15+
return ans

0 commit comments

Comments
 (0)