-
Notifications
You must be signed in to change notification settings - Fork 3
/
1630.cpp
30 lines (30 loc) · 903 Bytes
/
1630.cpp
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
class Solution {
public:
vector<bool> checkArithmeticSubarrays(vector<int>& nums, vector<int>& l, vector<int>& r) {
int m = nums.size();
int n = l.size();
vector<bool> res;
for (int i = 0; i < n; ++i) {
int left = l[i];
int right = r[i];
vector<int> meta;
for (int j = left; j <= right; ++j) {
meta.push_back(nums[j]);
}
sort(meta.begin(), meta.end());
unordered_set<int> st;
int k = meta.size();
bool ans = true;
for (int j = 0; j < k - 1; ++j) {
int diff = meta[j + 1] - meta[j];
st.insert(diff);
if (st.size() > 1) {
ans = false;
break;
}
}
res.push_back(ans);
}
return res;
}
};