1630.cpp (756B)
1 class Solution { 2 public: 3 vector<bool> checkArithmeticSubarrays(const vector<int> &nums, const vector<int> &l, 4 const vector<int> &r) { 5 int n = nums.size(), m = l.size(); 6 vector<bool> res(m, true); 7 for (int q = 0; q < m; q++) { 8 if (r[q] - l[q] < 2) continue; 9 vector<int> range(nums.begin() + l[q], nums.begin() + r[q] + 1); 10 sort(range.begin(), range.end()); 11 const int diff = range[1] - range[0]; 12 for (int i = 2; i < range.size(); i++) { 13 if (range[i] - range[i - 1] != diff) { 14 res[q] = false; 15 break; 16 } 17 } 18 } 19 return res; 20 } 21 };