Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8549b4e

Browse files
committedDec 27, 2021
Add solution #1668
1 parent b2aab49 commit 8549b4e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
1550|[Three Consecutive Odds](./1550-three-consecutive-odds.js)|Easy|
188188
1551|[Minimum Operations to Make Array Equal](./1551-minimum-operations-to-make-array-equal.js)|Medium|
189189
1598|[Crawler Log Folder](./1598-crawler-log-folder.js)|Easy|
190+
1668|[Maximum Repeating Substring](./1668-maximum-repeating-substring.js)|Easy|
190191
1780|[Check if Number is a Sum of Powers of Three](./1780-check-if-number-is-a-sum-of-powers-of-three.js)|Medium|
191192
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|
192193
1929|[Concatenation of Array](./1929-concatenation-of-array.js)|Easy|
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 1668. Maximum Repeating Substring
3+
* https://leetcode.com/problems/maximum-repeating-substring/
4+
* Difficulty: Easy
5+
*
6+
* For a string sequence, a string word is k-repeating if word concatenated k times is a substring
7+
* of sequence. The word's maximum k-repeating value is the highest value k where word is k-repeating
8+
* in sequence. If word is not a substring of sequence, word's maximum k-repeating value is 0.
9+
*
10+
* Given strings sequence and word, return the maximum k-repeating value of word in sequence.
11+
*/
12+
13+
/**
14+
* @param {string} sequence
15+
* @param {string} word
16+
* @return {number}
17+
*/
18+
var maxRepeating = function(sequence, word) {
19+
let count = Math.floor(sequence.length / word.length) + 1;
20+
while (--count) {
21+
if (sequence.includes(word.repeat(count))) return count;
22+
}
23+
return count;
24+
};

0 commit comments

Comments
 (0)
Please sign in to comment.