[LeetCode] Special Array I

3151. Special Array I

An array is considered special if every pair of its adjacent elements contains two numbers with different parity.

You are given an array of integers nums. Return true if nums is a special array, otherwise, return false.

1
2
3
4
5
6
7
8
9
10
class Solution {
public:
bool isArraySpecial(vector<int>& nums) {
for(int i = 0; i < nums.size() - 1; i++) {
if((nums[i] ^ nums[i+1]) % 2 == 0) return false;
}
return true;
}
};

Author: Song Hayoung
Link: https://songhayoung.github.io/2024/05/19/PS/LeetCode/special-array-i/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.