2399. Check Distances Between Same Letters

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

Содержание

LeetCode problem 2399

class Solution:
    def checkDistances(self, s: str, distance: List[int]) -> bool:
        d = defaultdict(int)
        for i, c in enumerate(s, 1):
            if d[c] and i - d[c] - 1 != distance[ord(c) - ord('a')]:
                return False
            d[c] = i
        return True