-
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
package com.fishercoder.solutions.fourththousand;
import java.util.Arrays;
public class _3254 {
public static class Solution1 {
public int[] resultsArray(int[] nums, int k) {
int n = nums.length;
int[] ans = new int[n - k + 1];
boolean sorted;
if (k == 1) {
return nums;
}
Arrays.fill(ans, -1);
for (int i = 0; i <= n - k; i++) {
sorted = true;
for (int j = i + 1; j < i + k; j++) {
if (nums[j] != nums[j - 1] + 1) {
sorted = false;
break;
}
}
if (sorted) {
ans[i] = nums[i + k - 1];
}
}
return ans;
}
}
}