Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7.

A string is homogenous if all the characters of the string are the same.

A substring is a contiguous sequence of characters within a string.

&nbsp;
Example 1:

Input: s = "abbcccaa"
Output: 13
Explanation: The homogenous substrings are listed as below:
"a"   appears 3 times.
"aa"  appears 1 time.
"b"   appears 2 times.
"bb"  appears 1 time.
"c"   appears 3 times.
"cc"  appears 2 times.
"ccc" appears 1 time.
3 + 1 + 2 + 1 + 3 + 2 + 1 = 13.

Example 2:

Input: s = "xy"
Output: 2
Explanation: The homogenous substrings are "x" and "y".

Example 3:

Input: s = "zzzzz"
Output: 15


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 105
	s consists of lowercase letters.

class Solution:
    def countHomogenous(self, s: str) -> int:
        res, count, n = 0, 1, len(s)
        for i in range(1,n):
            if s[i]==s[i-1]:
                count+=1
            else:
                if count>1:
                    res+=(count*(count-1)//2)
                count=1    
        if count>1:
            res+=(count*(count-1)//2)
        return (res+n)%(10**9+7)
class Solution {
    public int countHomogenous(String s) {
        int res = 1;
        int carry = 1;
        int mod = 1000000007;
        for(int i =1;i<s.length();i++){
            if(s.charAt(i) == s.charAt(i-1)) carry++;
            else carry = 1;
            res = (res + carry) % mod;
        }

        return res;

    }
}
class Solution {
public:
    int countHomogenous(string s) {
        int mod=1e9+7,size=s.size(),i=0,j=0,count=0;
        while(j<size){
            if(s[j]!=s[j+1]){
                long n=j-i+1;
                count = count + (n*(n+1)/2)%mod;
                i=j+1;
            }
            j++;
        }
        return count;
    }
};
var countHomogenous = function(s) {
    let mod = 1e9 + 7
    let n = s.length
    let j=0, res = 0
    
    for(let i=0; i<n; i++){
        if(i>0 && s[i-1] != s[i]){
            let x = i-j
            res += x*(x+1) / 2
            j = i
        }
    }
    
    let x = n-j
    res += x*(x+1) / 2

    return res%mod
};
Count Number of Homogenous Substrings