File tree 3 files changed +58
-0
lines changed
solution/1700-1799/1759.Count Number of Homogenous Substrings
3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -268,6 +268,27 @@ int countHomogenous(char* s) {
268
268
}
269
269
```
270
270
271
+ ### **C#**
272
+
273
+ ```cs
274
+ public class Solution {
275
+ public int CountHomogenous(string s) {
276
+ long MOD = 1000000007;
277
+ long ans = 0;
278
+ for (int i = 0, j = 0; i < s.Length; i = j) {
279
+ j = i;
280
+ while (j < s.Length && s[j] == s[i]) {
281
+ ++j;
282
+ }
283
+ int cnt = j - i;
284
+ ans += (long) (1 + cnt) * cnt / 2;
285
+ ans %= MOD;
286
+ }
287
+ return (int) ans;
288
+ }
289
+ }
290
+ ```
291
+
271
292
### ** ...**
272
293
273
294
```
Original file line number Diff line number Diff line change @@ -250,6 +250,27 @@ int countHomogenous(char* s) {
250
250
}
251
251
```
252
252
253
+ ### **C#**
254
+
255
+ ```cs
256
+ public class Solution {
257
+ public int CountHomogenous(string s) {
258
+ long MOD = 1000000007;
259
+ long ans = 0;
260
+ for (int i = 0, j = 0; i < s.Length; i = j) {
261
+ j = i;
262
+ while (j < s.Length && s[j] == s[i]) {
263
+ ++j;
264
+ }
265
+ int cnt = j - i;
266
+ ans += (long) (1 + cnt) * cnt / 2;
267
+ ans %= MOD;
268
+ }
269
+ return (int) ans;
270
+ }
271
+ }
272
+ ```
273
+
253
274
### ** ...**
254
275
255
276
```
Original file line number Diff line number Diff line change
1
+ public class Solution {
2
+ public int CountHomogenous ( string s ) {
3
+ long MOD = 1000000007 ;
4
+ long ans = 0 ;
5
+ for ( int i = 0 , j = 0 ; i < s . Length ; i = j ) {
6
+ j = i ;
7
+ while ( j < s . Length && s [ j ] == s [ i ] ) {
8
+ ++ j ;
9
+ }
10
+ int cnt = j - i ;
11
+ ans += ( long ) ( 1 + cnt ) * cnt / 2 ;
12
+ ans %= MOD ;
13
+ }
14
+ return ( int ) ans ;
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments