We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 52f0793 commit f514b85Copy full SHA for f514b85
3152-special-array-ii/3152-special-array-ii.java
@@ -0,0 +1,28 @@
1
+class Solution {
2
+ public boolean[] isArraySpecial(int[] nums, int[][] queries) {
3
+ // if both odd or even - incr cnt
4
+
5
6
7
+ int n = nums.length;
8
+ int[] pfsum = new int[n];
9
+ pfsum[0] = 0;
10
+ for(int i=1;i<n;i++){
11
+ pfsum[i] = pfsum[i-1];
12
+ if(((nums[i]&1)!=1 && (nums[i-1]&1)!=1) || ((nums[i]&1)==1 && (nums[i-1]&1)==1)){
13
+ pfsum[i]++;
14
+ }
15
16
17
+ //queries :
18
+ boolean res[] = new boolean[queries.length];
19
+ int k=0;
20
+ for(int[] q : queries){
21
+ //start && end same :
22
+ int cnt = pfsum[q[1]] - ((q[0]>0)?pfsum[q[0]]:0);
23
+ res[k] = (cnt==0)?true:false;
24
+ k++;
25
26
+ return res;
27
28
+}
0 commit comments