ans
to 0
to store the final count of homogenous substrings.currStreak
to 0
to keep track of the current streak of identical characters.MOD
as 10^9 + 7
for modulo operations.i
of the string s
:
a. If i == 0
or s[i] == s[i - 1]
, increment currStreak
.
b. Otherwise, reset currStreak
to 1
.
c. Add currStreak
to ans
modulo MOD
.ans
.