Package g3101_3200.s3151_special_array_i
Class Solution
-
- All Implemented Interfaces:
public final class Solution
3151 - Special Array I\.
Easy
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
. Returntrue
ifnums
is a special array, otherwise, returnfalse
.Example 1:
Input: nums = 1
Output: true
Explanation:
There is only one element. So the answer is
true
.Example 2:
Input: nums = 2,1,4
Output: true
Explanation:
There is only two pairs:
(2,1)
and(1,4)
, and both of them contain numbers with different parity. So the answer istrue
.Example 3:
Input: nums = 4,3,1,6
Output: false
Explanation:
nums[1]
andnums[2]
are both odd. So the answer isfalse
.Constraints:
1 <= nums.length <= 100
1 <= nums[i] <= 100
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final Boolean
isArraySpecial(IntArray nums)
-
-
Method Detail
-
isArraySpecial
final Boolean isArraySpecial(IntArray nums)
-
-
-
-