forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1566.java
26 lines (24 loc) · 834 Bytes
/
_1566.java
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
package com.fishercoder.solutions;
import java.util.Arrays;
public class _1566 {
public static class Solution1 {
public boolean containsPattern(int[] arr, int m, int k) {
for (int i = 0; i < arr.length - m; i++) {
int[] pattern = Arrays.copyOfRange(arr, i, i + m);
int times = 1;
for (int j = i + m; j < arr.length; j += m) {
int[] candidate = Arrays.copyOfRange(arr, j, j + m);
if (Arrays.equals(pattern, candidate)) {
times++;
if (times == k) {
return true;
}
} else {
break;
}
}
}
return false;
}
}
}