Detect Pattern of Length M Repeated K or More Times LeetCode solution in Java

1
// Time complexity: O(N)
2
// Space complexity: O(1)
3
class Solution {
4
public boolean containsPattern(int[] arr, int m, int k) {
5
int count = 0;
6
for (int i = 0; i < arr.length - m; i++) {
7
if (arr[i] == arr[i + m]) {
8
count++;
9
} else {
10
count = 0;
11
}
12
if (count == m * (k - 1)) {
13
return true;
14
}
15
}
16
return false;
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0