Get Equal Substrings Within Budget LeetCode solution in Python

1
class Solution(object):
2
def equalSubstring(self, s, t, maxCost):
3
"""
4
:type s: str
5
:type t: str
6
:type maxCost: int
7
:rtype: int
8
"""
9

10
best = 0
11

12
windowCost = 0
13
l = 0
14
for r in range(len(s)):
15

16
windowCost += abs(ord(s[r]) - ord(t[r]))
17

18
while windowCost > maxCost:
19

20
windowCost -= abs(ord(s[l]) - ord(t[l]))
21
l += 1
22

23
best = max(best, r - l + 1)
24

25
return best

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0