1208. Get Equal Substrings Within Budget

class Solution:
    def equalSubstring(self, s: str, t: str, maxCost: int) -> int:
        diff = []
        for i, e in enumerate(s):
            diff.append(abs(ord(s[i]) - ord(t[i])))

        left = 0
        temp = 0
        ans = 0  

        for right in range(len(s)):
            temp += diff[right]

            while temp > maxCost:
                temp -= diff[left]
                left += 1

            ans = max(ans, right - left + 1)

        return ans