#87. 连续三数奇偶性判断
连续三数奇偶性判断
Consecutive Parity
Background
Congcong is currently studying the properties of number sequences. He wants to determine if an integer array contains three consecutive numbers that all share the same parity.
Problem Description
Given an array of integers, return true if the array contains either three consecutive even values or three consecutive odd values; otherwise, return false.
Input Format
The input is given from standard input in the following format.
The input consists of a single line containing space-separated integers, representing the array.
Output Format
Output to standard output in the following format.
Output a single line:
trueif the array contains three consecutive even or three consecutive odd values, andfalseotherwise.
Sample
2 1 3 5
true
2 1 2 5
false
2 4 2 5
true
Sample Explanation
Sample 1: The array is [2 1 3 5]. The numbers 1, 3, 5 are three consecutive odd numbers, so it returns true.
Sample 2: The array is [2 1 2 5]. There are no three consecutive even numbers, nor three consecutive odd numbers, so it returns false.
Sample 3: The array is [2 4 2 5]. The numbers 2, 4, 2 are three consecutive even numbers, so it returns true.
Constraints
The length of the array satisfies . Each element in the array satisfies . Time limit: 1 second, Memory limit: 1024 MB.