#3151
Easy Algorithms Special array i
Array
81.6% acceptance
Feb 24, 2026
580
33
An array is considered special if the parity of every pair of adjacent elements is different.
In other words, one element in each pair must be even, and the other must be odd.
You are given an array of integers nums. Return true if nums is a special array, otherwise false.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn is_array_special(nums: Vec<i32>) -> bool {
nums.windows(2).all(|w| (w[0] % 2) != (w[1] % 2))
}
}