想到滑窗这题就毫无难度
def equalSubstring(self, s, t, maxCost):
"""
:type s: str
:type t: str
:type maxCost: int
:rtype: int
"""
res = 0
l = 0
for r in range(len(s)):
maxCost -= abs(ord(t[r])-ord(s[r]))
while l <= r and maxCost < 0:
maxCost += abs(ord(t[l]) - ord(s[l]))
l += 1
res = max(r-l+1,res)
return res