aboutsummaryrefslogtreecommitdiff
path: root/special_array.py
blob: 43f1c5c1950b681d7289138575f4ffe09c914b8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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'.
"""


class Solution(object):
    def isArraySpecial(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        for i in range(1, len(nums)):
            if (nums[i - 1] & 1) ^ (nums[i] & 1) == 0:
                return False
        return True


if __name__ == "__main__":
    obj = Solution()
    print(obj.isArraySpecial(nums=[1]))
    print(obj.isArraySpecial(nums=[2, 1, 4]))
    print(obj.isArraySpecial(nums=[4, 3, 1, 6]))