3151: Special-Array-I
Easy
Simply, iterate through the array and check that the parity of the previous element is different from the parity of the current element
## Code<span>:</span>
class Solution {
public:
bool isArraySpecial(vector<int>& nums) {
int parity = nums[0] % 2;
for (int i = 1; i < nums.size(); ++i) {
if (parity != nums[i] % 2) {
^= 1;
parity } else {
return false;
}
}
return true;
}
};