注意:
vector<int> a(b.begin() + l,a.begin() + r ), 范围是下标[l,r) 左闭右开区间
class Solution {
public:
vector<bool> checkArithmeticSubarrays(vector<int>& nums, vector<int>& l, vector<int>& r) {
int n = l.size();
vector<bool> res;
for(int i = 0; i < n; i ++ ){
int t = r[i] - l[i] + 1;
if(t == 1){
res.push_back(true);
continue;
}
vector<int> a(nums.begin() + l[i], nums.begin() + r[i] + 1 );
sort(a.begin(),a.end());
int tmp = a[1] - a[0];
bool ok = true;
for(int j = 1; j < t; j ++ ){
if(a[j] - a[j-1] != tmp){
ok = false;
break;
}
}
res.push_back(ok);
}
return res;
}
};