# 1759. 统计同构子字符串的数目

class Solution {
public:
int countHomogenous(string s) {
long long MOD = 1e9 + 7;
int left = 0;
long long ans = 0;
for (int i = 1; i < s.length(); i++) {
if (s[i] != s[left]) {
ans += (i - left) * (i - left + 1) / 2;
ans %= MOD;
left = i;
}
}
ans += (s.length() - left) * (s.length() + 1 - left) / 2;
return ans % MOD;
}
};