Skip to content

Commit 74e4a12

Browse files
committed
Add solution #1566
1 parent 8549b4e commit 74e4a12

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
1507|[Reformat Date](./1507-reformat-date.js)|Easy|
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|
189+
1566|[Detect Pattern of Length M Repeated K or More Times](./1566-detect-pattern-of-length-m-repeated-k-or-more-times.js)|Easy|
189190
1598|[Crawler Log Folder](./1598-crawler-log-folder.js)|Easy|
190191
1668|[Maximum Repeating Substring](./1668-maximum-repeating-substring.js)|Easy|
191192
1780|[Check if Number is a Sum of Powers of Three](./1780-check-if-number-is-a-sum-of-powers-of-three.js)|Medium|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 1566. Detect Pattern of Length M Repeated K or More Times
3+
* https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times/
4+
* Difficulty: Easy
5+
*
6+
* Given an array of positive integers arr, find a pattern of length m that is repeated k or more times.
7+
*
8+
* A pattern is a subarray (consecutive sub-sequence) that consists of one or more values, repeated multiple
9+
* times consecutively without overlapping. A pattern is defined by its length and the number of repetitions.
10+
*
11+
* Return true if there exists a pattern of length m that is repeated k or more times, otherwise return false.
12+
*/
13+
14+
/**
15+
* @param {number[]} arr
16+
* @param {number} m
17+
* @param {number} k
18+
* @return {boolean}
19+
*/
20+
var containsPattern = function(arr, m, k) {
21+
for (let i = 0; i < arr.length - m + 1; i++) {
22+
const pattern = new Array(k).fill(arr.slice(i, i + m).join()).join();
23+
if (arr.join().includes(pattern)) {
24+
return true;
25+
}
26+
}
27+
return false;
28+
};

0 commit comments

Comments
 (0)