#88. 数组中数字3的出现次数与相邻性
数组中数字3的出现次数与相邻性
Exact Three Threes
Background
Congcong has recently been studying array properties. He encountered an interesting problem that requires determining if an array satisfies specific conditions.
Problem Description
Given an array of integers, return true if the value appears in the array exactly times, and no two 's are next to each other; otherwise, return false.
Input Format
The input consists of a single line representing an integer array. Array elements are separated by spaces and enclosed in square brackets [].
[A_1 A_2 ... A_N]
Output Format
Output to standard output in the following format.
Output
trueif the conditions are met; otherwise, outputfalse.
Sample
[3 1 3 1 3]
true
[3 1 3 3]
false
[3 4 3 3 4]
false
Sample Explanation
Sample 1: In the array [3 1 3 1 3], the number appears times, and no two 's are adjacent. Thus, the output is true.
Sample 2: In the array [3 1 3 3], the number appears times, but the last two 's are adjacent. Thus, the output is false.
Sample 3: In the array [3 4 3 3 4], the number appears times, but the middle two 's are adjacent. Thus, the output is false.
Constraints
The length of the array satisfies . Each element in the array satisfies . Time limit: second, Memory limit: KiB.