等差数列求和
typedef long long ll;
const int mod = 1e9+7;
class Solution {
public:
int countHomogenous(string s) {
int n=s.size();
ll cnt=0;
ll res=0;
for(int i=0;i<n;i++)
{
if(i&&s[i]!=s[i-1])
{
res=(res+(1ll+cnt)*cnt/2)%mod;
cnt=1;
}
else cnt++;
}
res=(res+(1ll+cnt)*cnt/2)%mod;
return res;
}
};