1180. Count Substrings with Only One Distinct Letter

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

Содержание

LeetCode problem 1180

class Solution:
    def countLetters(self, s: str) -> int:
        res = 0
        i, n = 0, len(s)
        while i < n:
            j = i
            cnt = 0
            while j < n and s[j] == s[i]:
                j += 1
                cnt += 1
                res += cnt
            i = j
        return res