Skip to content

Latest commit

 

History

History
19 lines (17 loc) · 475 Bytes

2399.md

File metadata and controls

19 lines (17 loc) · 475 Bytes

2399. Check Distances Between Same Letters

Solution 1 (time O(n), space O(1))

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