-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
27 lines (21 loc) · 856 Bytes
/
Solution.cs
File metadata and controls
27 lines (21 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System.Text;
namespace LeetCode.Problem1668{
//1668. Maximum Repeating Substring
//https://leetcode.com/problems/maximum-repeating-substring/
/*
For a string sequence, a string word is k-repeating if word concatenated k times is a substring of sequence.
The word's maximum k-repeating value is the highest value k where word is k-repeating in sequence.
If word is not a substring of sequence, word's maximum k-repeating value is 0.
Given strings sequence and word, return the maximum k-repeating value of word in sequence.
*/
public class Solution {
public int MaxRepeating(string sequence, string word) {
StringBuilder sb = new StringBuilder();
while (sequence.Contains(sb.ToString()))
{
sb.Append(word);
}
return (sb.Length - word.Length) / word.Length;
}
}
}