1759. Count Number of Homogenous Substrings

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

On This Page

LeetCode problem 1759

class Solution:
    def countHomogenous(self, s: str) -> int:
        mod = 10**9 + 7
        res = cnt = 1
        for a, b in pairwise(s):
            cnt = cnt + 1 if a == b else 1
            res = (res + cnt) % mod
        return res