Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
472 B
6
Indexable
Never
/* 
parity==true(if the both consecutive elements are even or both odd) 
check for any consecutive elements are of same parity if it is is return false if not then return true at last
*/

class Solution {
    public boolean isArraySpecial(int[] nums) {
        for(int i=0;i<nums.length-1;i++)
        {
            if(nums[i]%2==0&&nums[i+1]%2==0)return false;
            if(nums[i]%2==1&&nums[i+1]%2==1)return false;
        }
        return true;
    }
}
Leave a Comment