Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1b891ce

Browse files
feat: add cs solution to lc problem: No.1759 (doocs#1947)
1 parent ec90a50 commit 1b891ce

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

‎solution/1700-1799/1759.Count Number of Homogenous Substrings/README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,27 @@ int countHomogenous(char* s) {
268268
}
269269
```
270270
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+
271292
### **...**
272293

273294
```

‎solution/1700-1799/1759.Count Number of Homogenous Substrings/README_EN.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,27 @@ int countHomogenous(char* s) {
250250
}
251251
```
252252
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+
253274
### **...**
254275

255276
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /