Count Number of Homogenous Substrings LeetCode solution in Java

1
class Solution {
2
public int countHomogenous(String s) {
3
int res = 1;
4
int carry = 1;
5
int mod = 1000000007;
6
for (int i = 1; i < s.length(); i++) {
7
if (s.charAt(i) == s.charAt(i - 1)) carry++;
8
else carry = 1;
9
res = (res + carry) % mod;
10
}
11

12
return res;
13
}
14
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0