@@ -121,6 +121,73 @@ func maxRepeating(sequence string, word string) int {
121
121
}
122
122
```
123
123
124
+ ### ** C**
125
+
126
+ ``` c
127
+ #define max (a,b ) (((a) > (b)) ? (a) : (b))
128
+
129
+ int findWord (int i, char * sequence, char * word) {
130
+ int n = strlen(word);
131
+ for (int j = 0; j < n; j++) {
132
+ if (sequence[ j + i] != word[ j] ) {
133
+ return 0;
134
+ }
135
+ }
136
+ return 1 + findWord(i + n, sequence, word);
137
+ }
138
+
139
+ int maxRepeating(char * sequence, char * word) {
140
+ int n = strlen(sequence);
141
+ int m = strlen(word);
142
+ int ans = 0;
143
+ for (int i = 0; i <= n - m; i++) {
144
+ ans = max(ans, findWord(i, sequence, word));
145
+ }
146
+ return ans;
147
+ }
148
+ ```
149
+
150
+ ### **TypeScript**
151
+
152
+ ```ts
153
+ function maxRepeating(sequence: string, word: string): number {
154
+ let n = sequence.length;
155
+ let m = word.length;
156
+ for (let k = Math.floor(n / m); k > 0; k--) {
157
+ if (sequence.includes(word.repeat(k))) {
158
+ return k;
159
+ }
160
+ }
161
+ return 0;
162
+ }
163
+ ```
164
+
165
+ ### ** Rust**
166
+
167
+ ``` rust
168
+ impl Solution {
169
+ pub fn max_repeating (sequence : String , word : String ) -> i32 {
170
+ let n = sequence . len ();
171
+ let m = word . len ();
172
+ if n < m {
173
+ return 0 ;
174
+ }
175
+ let mut dp = vec! [0 ; n - m + 1 ];
176
+ for i in 0 ..= n - m {
177
+ let s = & sequence [i .. i + m ];
178
+ if s == word {
179
+ dp [i ] = if (i as i32 ) - (m as i32 ) < 0 {
180
+ 0
181
+ } else {
182
+ dp [i - m ]
183
+ } + 1 ;
184
+ }
185
+ }
186
+ * dp . iter (). max (). unwrap ()
187
+ }
188
+ }
189
+ ```
190
+
124
191
### ** ...**
125
192
126
193
```
0 commit comments