#89. 检查数字2的相邻性
检查数字2的相邻性
Check Adjacency of Twos
Background
Congcong has been studying the properties of number sequences recently. He noticed that when certain numbers appear in a sequence, they always like to be next to another identical number. He wants your help to verify a specific rule.
Problem Description
Given an array of integers, return true if every that appears in the array is next to another ; otherwise, return false.
Input Format
Input is given from standard input in the following format.
A single line containing several integers, representing the elements of the array.
Output Format
Output is printed to standard output in the following format.
Output
trueif the condition is met, otherwise outputfalse.
Sample
4 2 2 3
true
2 2 4
true
2 2 4 2
false
Sample Explanation
- Sample 1: In the array
[4 2 2 3], there are two s, and they are adjacent, sotrueis returned. - Sample 2: In the array
[2 2 4], there are two s, and they are adjacent, sotrueis returned. - Sample 3: In the array
[2 2 4 2], there are three s. The first two s are adjacent, but the last is next to a and not another , sofalseis returned.
Constraints
Time limit: second, Memory limit: KiB for each test case.