#73. 检查数组中是否存在相邻的2

    ID: 73 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-2gesp1循环结构条件结构

检查数组中是否存在相邻的2

Contains Adjacent Twos

Background

Congcong is currently learning about array operations and has encountered an interesting problem. He wants to determine if an integer array contains two adjacent elements that are both the number 2.

Problem Description

Given an array of integers, return true if the array contains a 2 next to a 2 somewhere. Otherwise, return false.

Input Format

The input is given from standard input in the following format.

An array of integers, with elements separated by spaces.

Output Format

The output should be printed to standard output in the following format.

Output true if the array contains two adjacent 2s; otherwise, output false.

Sample

1 2 2
true
1 2 1 2
false
2 1 2
false

Sample Explanation

In Sample 1, the array [1, 2, 2] contains two adjacent 2s at indices 1 and 2, so it returns true. In Sample 2, the array [1, 2, 1, 2] does not contain adjacent 2s, so it returns false. In Sample 3, the array [2, 1, 2] does not contain adjacent 2s, so it returns false.

Constraints

Time limit: 1 second. Memory limit: 1024 KiB for each test case.