Skip to content

Commit 8e9211e

Browse files
authored
Added Count Number of Homogenous Substrings.java
1 parent 65e2fba commit 8e9211e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
private final int MOD = 1000000007;
3+
public int countHomogenous(String s) {
4+
int count = 0;
5+
int start = 0;
6+
int end = 0;
7+
int n = s.length();
8+
while (end < n) {
9+
if (s.charAt(start) == s.charAt(end)) {
10+
count = (count + (end - start + 1)) % MOD;
11+
end++;
12+
} else {
13+
start++;
14+
}
15+
}
16+
return count;
17+
}
18+
}

0 commit comments

Comments
 (0)