8000 Create December-09.cpp · Hunterdii/Leetcode-POTD@9addac9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9addac9

Browse files
authored
Create December-09.cpp
1 parent a94cad5 commit 9addac9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
vector<bool> isArraySpecial(vector<int>& nums, vector<vector<int>>& queries) {
4+
int n = nums.size();
5+
vector<int> d(n);
6+
iota(d.begin(), d.end(), 0);
7+
for (int i = 1; i < n; ++i) {
8+
if (nums[i] % 2 != nums[i - 1] % 2) {
9+
d[i] = d[i - 1];
10+
}
11+
}
12+
vector<bool> ans;
13+
for (auto& q : queries) {
14+
ans.push_back(d[q[1]] <= q[0]);
15+
}
16+
return ans;
17+
}
18+
};

0 commit comments

Comments
 (0)
0