class Solution:
def equalSubstring(self, s: str, t: str, maxCost: int) -> int:
start = 0
end = 0
ans = 0
res = 0
while end < len(s) and start < len(s):
ans = ans + abs(ord(s[end])-ord(t[end]))
if ans > maxCost:
ans = ans - abs(ord(s[start])-ord(t[start]))
start = start + 1
end = end + 1
else:
end = end + 1
res = max(res, end-start)
return res
02-20
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-05
1420
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)