1180. Count Substrings with Only One Distinct Letter

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

On This Page

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