1794. Count Pairs of Equal Substrings With Minimum Difference

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1794

class Solution:
    def countQuadruples(self, firstString: str, secondString: str) -> int:
        last = {c: i for i, c in enumerate(secondString)}
        res, mi = 0, inf
        for i, c in enumerate(firstString):
            if c in last:
                t = i - last[c]
                if mi > t:
                    mi = t
                    res = 1
                elif mi == t:
                    res += 1
        return res