Today’s problem
https://leetcode.com/problems/special-array-i/description/
Intuition
Do what the question ask.
Approach
Iterate through the array, then check whether the two number has the are both odd or even or not.
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