#82. 判断值是否在相邻元素对中无处不在
判断值是否在相邻元素对中无处不在
Value Everywhere
Background
Dawei is designing a sequence checking system. He needs to determine if a specific value is "everywhere" in a sequence.
Problem Description
We'll say that a value is "everywhere" in an array if for every pair of adjacent elements in the array, at least one of the pair is that value. Return true if the given value is everywhere in the array.
Input Format
Input is given from standard input in the following format.
The first line contains an integer array
arrand an integerval.
Output Format
Output is printed to standard output in the following format.
Output
trueifvalis everywhere inarr; otherwise outputfalse.
Sample
[1 2 1 3] 1
true
[1 2 1 3] 2
false
[1 2 1 3 4] 1
false
Sample Explanation
Sample 1: For array [1 2 1 3] and value 1.
The adjacent pairs are (1, 2), (2, 1), (1, 3).
(1, 2)contains1.(2, 1)contains1.(1, 3)contains1. All adjacent pairs contain1, sotrueis returned.
Sample 2: For array [1 2 1 3] and value 2.
The adjacent pairs are (1, 2), (2, 1), (1, 3).
(1, 2)contains2.(2, 1)contains2.(1, 3)does not contain2. Not all adjacent pairs contain2, sofalseis returned.
Sample 3: For array [1 2 1 3 4] and value 1.
The adjacent pairs are (1, 2), (2, 1), (1, 3), (3, 4).
(3, 4)does not contain1. Not all adjacent pairs contain1, sofalseis returned.
Constraints
- The length of the array
arr, , satisfies . - Elements in
arrandvalsatisfy .