Get Equal Substrings Within Budget LeetCode solution in Python
1class Solution(object):2def equalSubstring(self, s, t, maxCost):3"""4:type s: str5:type t: str6:type maxCost: int7:rtype: int8"""910best = 01112windowCost = 013l = 014for r in range(len(s)):1516windowCost += abs(ord(s[r]) - ord(t[r]))1718while windowCost > maxCost:1920windowCost -= abs(ord(s[l]) - ord(t[l]))21l += 12223best = max(best, r - l + 1)2425return best