Can Convert String in K Moves LeetCode solution in Python

1
# Runtime: 285 ms (Top 92.79%) | Memory: 15.1 MB (Top 75.68%)
2
class Solution:
3
def canConvertString(self, s: str, t: str, k: int) -> bool:
4
if len(s) != len(t):
5
return False
6

7
cycles, extra = divmod(k, 26)
8
shifts = [cycles + (shift <= extra) for shift in range(26)]
9

10
for cs, ct in zip(s, t):
11
shift = (ord(ct) - ord(cs)) % 26
12
if shift == 0:
13
continue
14
if not shifts[shift]:
15
return False
16
shifts[shift] -= 1
17

18
return True

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0