-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspecial_array.c
More file actions
51 lines (46 loc) · 1.36 KB
/
special_array.c
File metadata and controls
51 lines (46 loc) · 1.36 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*An array is considered special if the parity of every pair of adjacent elements is different. In other words, one element in each pair must be even, and the other must be odd.
You are given an array of integers nums. Return true if nums is a special array, otherwise, return false.
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 is true.
Example 3:
Input: nums = [4,3,1,6]
Output: false
Explanation:
nums[1] and nums[2] are both odd. So the answer is false.
Constraints:
1 <= nums.length <= 100
1 <= nums[i] <= 100
*/
bool isArraySpecial(int* nums, int numsSize) {
bool flag;
if (numsSize<=100){
if(numsSize>1){
for(int i=0;i<numsSize-1;i++){
if(nums[i]>=1 && nums[i]<=100)
{
if (nums[i+1]>=1 && nums[i+1]<=100){
if(nums[i]%2==0 && nums[i+1]%2!=0){
continue;
}
else if(nums[i+1]%2==0 && nums[i]%2!=0){
continue;
}
else{
return false;
}
}
}
}
}
return true;
}
return false;
}