Problem: 3152. 特殊数组 II
👨🏫 参考题解
Code
class Solution {
public boolean[] isArraySpecial(int[] nums, int[][] queries) {
int[] s = new int[nums.length];
for (int i = 1; i < nums.length; i++) {
s[i] = s[i - 1] + (nums[i - 1] % 2 == nums[i] % 2 ? 1 : 0);
}
boolean[] ans = new boolean[queries.length];
for (int i = 0; i < queries.length; i++) {
int[] q = queries[i];
ans[i] = s[q[0]] == s[q[1]];
}
return ans;
}
}