Today’s Problem

https://leetcode.com/problems/special-array-i/description/

Approach

Simulate directly as required by the problem statement.

Method

Iterate through the array and check whether each adjacent pair of numbers is both odd or both even.

Complexity

  • Time complexity: $O(N)$

  • Space complexity: $O(1)$

Code

class Solution:
    def isArraySpecial(self, nums: List[int]) -> bool:
        for i in range(1, len(nums)):
            if (nums[i] - nums[i-1]) % 2 == 0:
                return False
        
        return True