File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
LeetCode/CountNumberofHomogenousSubstrings Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ #include < gtest/gtest.h>
3
+
4
+ using namespace std ;
5
+
6
+ class Solution {
7
+ public:
8
+ int countHomogenous (string s) {
9
+ if (s.empty ()) return 0 ;
10
+ long ret = 0 ;
11
+ int len = s.size ();
12
+ int lasti = 0 ;
13
+ char last = s[0 ];
14
+ for (int i = 1 ; i < len; i++) {
15
+ if (s[i] == last) {
16
+ continue ;
17
+ } else {
18
+ ret += cal (i - lasti);
19
+ //
20
+ last = s[i];
21
+ lasti = i;
22
+ }
23
+ }
24
+ ret += cal (len - lasti);
25
+ return ret % long (1e9 + 7 );
26
+ }
27
+ private:
28
+ long cal (int n) {
29
+ return long (1 + n) * n / 2 ;
30
+ }
31
+ };
32
+
33
+ struct T {
34
+
35
+ };
36
+
37
+ TEST (Solution, test) {
38
+ T ts[] = {
39
+ {
40
+
41
+ },
42
+
43
+ };
44
+
45
+ for (T t : ts) {
46
+ Solution solution;
47
+
48
+ }
49
+ }
50
+
51
+ int main () {
52
+ testing::InitGoogleTest ();
53
+
54
+ return RUN_ALL_TESTS ();
55
+ }
56
+
57
+
You can’t perform that action at this time.
0 commit comments