-
Notifications
You must be signed in to change notification settings - Fork 14
/
1630-kir3i.cpp
41 lines (39 loc) · 1.11 KB
/
1630-kir3i.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
31
32
33
34
35
36
37
38
39
40
41
class Solution {
public:
unordered_set<int> s;
int smax, smin;
vector<bool> ans;
bool ok;
vector<bool> checkArithmeticSubarrays(vector<int>& nums, vector<int>& l, vector<int>& r) {
int qsz = l.size();
for (int q=0; q<qsz; q++) {
s.clear();
smax = -2e8;
smin = 2e8;
ok = true;
for(int i=l[q]; i<=r[q]; i++) {
s.insert(nums[i]);
smax = max(smax, nums[i]);
smin = min(smin, nums[i]);
}
int jump = (smax - smin) / (r[q] - l[q]);
if (smin == smax) {
ans.push_back(true);
continue;
} else if(!jump) {
ans.push_back(false);
continue;
}
for(int i=smin; i<=smax; i+=jump) {
if(!s.count(i)) {
ans.push_back(false);
ok = false;
break;
}
}
if (ok)
ans.push_back(true);
}
return ans;
}
};