/*
* @lc app=leetcode.cn id=1759 lang=typescript
*
* [1759] 统计同构子字符串的数目
*/
// @lc code=start
function countHomogenous(s: string): number {}
// @lc code=end
function countHomogenous(s: string): number {
const n = s.length,
MOD = 1e9 + 7
let res = 0
for (let i = 0, j = 0; i < n; i = ++j) {
while (s[j + 1] === s[j]) j++
let len = j - i + 1
res = (res + (len * (len + 1)) / 2) % MOD
}
return res
}
test.each([
{ input: { s: 'abbcccaa' }, output: 13 },
{ input: { s: 'xy' }, output: 2 },
{ input: { s: 'zzzzz' }, output: 15 },
])('input: s = $input.s', ({ input: { s }, output }) => {
expect(countHomogenous(s)).toEqual(output)
})