3254.cpp (483B)
1 class Solution { 2 public: 3 vector<int> resultsArray(const vector<int> &nums, int k) const { 4 const int n = size(nums); 5 vector<int> res(n - k + 1, -1); 6 7 for (int i = 0; i <= n - k; i++) { 8 for (int j = i + 1; j < i + k; j++) { 9 if (nums[j - 1] + 1 == nums[j]) continue; 10 i = j - 1; 11 goto next; 12 } 13 res[i] = nums[i + k - 1]; 14 next:; 15 } 16 17 return res; 18 } 19 };