diff options
author | Jack Sangdahl <[email protected]> | 2025-02-01 00:18:05 -0700 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-02-01 00:18:05 -0700 |
commit | a6a2deed1686008534328bf255c4fea92b72fd2e (patch) | |
tree | eda5d731f7e270f8c8301f3ee01ae0b451c90e9c /special_array.py | |
parent | 75fbc297a5534942c8daa977271fc8640653bdef (diff) | |
download | leetcode-a6a2deed1686008534328bf255c4fea92b72fd2e.tar.gz leetcode-a6a2deed1686008534328bf255c4fea92b72fd2e.zip |
3151. special array 1
Diffstat (limited to 'special_array.py')
-rw-r--r-- | special_array.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/special_array.py b/special_array.py new file mode 100644 index 0000000..43f1c5c --- /dev/null +++ b/special_array.py @@ -0,0 +1,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])) |