Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 536fe38

Browse files
Create 3255. Find the Power of K-Size Subarrays II.cpp
1 parent ddd121d commit 536fe38

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
vector<int> resultsArray(vector<int>& nums, int k) {
4+
int n = nums.size();
5+
vector<int>dp(n,0);
6+
dp[0] = 1;
7+
for(int i=1;i<n;i++){
8+
if(nums[i]-1==nums[i-1]){
9+
dp[i] = dp[i-1]+1;
10+
}else{
11+
dp[i] = 0;
12+
}
13+
}
14+
vector<int>ans;
15+
int i=0;
16+
int j = k-1;
17+
while(j<n){
18+
if(dp[j]-dp[i]+1==k) ans.push_back(nums[j]);
19+
else{
20+
ans.push_back(-1);
21+
}
22+
j++;
23+
i++;
24+
}
25+
return ans;
26+
}
27+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /