-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
36 lines (33 loc) · 761 Bytes
/
Solution.cs
File metadata and controls
36 lines (33 loc) · 761 Bytes
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
31
32
33
34
35
36
public class Solution
{
public int[] ResultsArray(int[] nums, int k)
{
if (k == 1) return nums;
int[] dp = new int[nums.Length];
dp[0] = 1;
for (int i = 1; i < nums.Length; i++)
{
if (nums[i] - nums[i - 1] == 1)
{
dp[i] = dp[i - 1] + 1;
}
else
{
dp[i] = 1;
}
}
int[] result = new int[nums.Length - k + 1];
for (int i = 0; i < result.Length; i++)
{
if (dp[i + k - 1] >= k)
{
result[i] = nums[i + k - 1];
}
else
{
result[i] = -1;
}
}
return result;
}
}