MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / shiftingLetters

Method shiftingLetters

String/ShiftingLetters.py:43–61  ·  view source on GitHub ↗

:type S: str :type shifts: List[int] :rtype: str

(self, S, shifts)

Source from the content-addressed store, hash-verified

41"""
42class Solution(object):
43 def shiftingLetters(self, S, shifts):
44 """
45 :type S: str
46 :type shifts: List[int]
47 :rtype: str
48 """
49
50 letters = "abcdefghijklmnopqrstuvwxyz"
51
52 new_s = []
53 old_index = 0
54 for i, j in zip(S[::-1], shifts[::-1]):
55 index = letters.index(i)
56
57 new_index = (index+j+old_index)%26
58
59 new_s.append(letters[new_index])
60 old_index += j
61 return ''.join(new_s[::-1])
62

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected