We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 326509d commit 679fb71Copy full SHA for 679fb71
3152. Special Array II
@@ -0,0 +1,40 @@
1
+class Solution {
2
+public:
3
+ bool check(int x, int y){
4
+ if((x+y)%2)return false;
5
+ return true;
6
+ }
7
+ vector<bool> isArraySpecial(vector<int>& a, vector<vector<int>>& q) {
8
+ int n=a.size();
9
+ vector<bool>ans;
10
+ if(n==1){
11
+ int size=q.size();
12
+ while(size--){
13
+ ans.push_back(true);
14
15
+ return ans;
16
17
+
18
+ vector<int>v(n,0);
19
+ if(check(a[0],a[1]))v[0]=1;
20
+ for(int i=1;i<a.size()-1;i++){
21
+ if(check(a[i],a[i+1]))v[i]=v[i-1]+1;
22
+ else v[i]=v[i-1];
23
24
+ v[n-1]=v[n-2];
25
26
+ for(int i=0;i<q.size();i++){
27
+ int l=q[i][0],r=q[i][1];
28
+ bool b=true;
29
+ if(l==r)b=true;
30
+ else if(v[r-1]-v[l]==0){
31
+ if(check(a[l],a[l+1]))b=false;
32
+ else b=true;
33
34
+ else b=false;
35
+ ans.push_back(b);
36
37
38
39
40
+};
0 commit comments