2399. Check Distances Between Same Letters

Updated: 2024-03-12
1 min read
[]

On This Page

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