- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3254.java
30 lines (28 loc) · 844 Bytes
/
_3254.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
27
28
29
30
packagecom.fishercoder.solutions.fourththousand;
importjava.util.Arrays;
publicclass_3254 {
publicstaticclassSolution1 {
publicint[] resultsArray(int[] nums, intk) {
intn = nums.length;
int[] ans = newint[n - k + 1];
booleansorted;
if (k == 1) {
returnnums;
}
Arrays.fill(ans, -1);
for (inti = 0; i <= n - k; i++) {
sorted = true;
for (intj = i + 1; j < i + k; j++) {
if (nums[j] != nums[j - 1] + 1) {
sorted = false;
break;
}
}
if (sorted) {
ans[i] = nums[i + k - 1];
}
}
returnans;
}
}
}