#260. 检查数组中是否存在三连击
检查数组中是否存在三连击
Check for Triples
Background
Congcong is playing a number game. He needs to check if a sequence of numbers contains three consecutive identical numbers. If it does, he cannot pass the current level.
Problem Description
Given an array of integers, we define a "triple" as a value appearing times in a row in the array. Return true if the array does not contain any triples; otherwise, return false.
Input Format
Input is given from standard input in the following format.
A single line containing multiple integers, representing the elements of the array. Elements are separated by spaces.
Output Format
Output is printed to standard output in the following format.
Output
trueif the array does not contain any triples; otherwise, outputfalse.
Sample
[1 1 2 2 1]
true
[1 1 2 2 2 1]
false
[1 1 1 2 2 2 1]
false
Sample Explanation
- Sample 1: The array is
[1 1 2 2 1]. There are no three consecutive identical numbers, so the output istrue. - Sample 2: The array is
[1 1 2 2 2 1]. The number appears three times consecutively, forming a "triple\