我必须计算数组中1,2,3的序列数,如下所示:
示例:
input: [1,2,3,1,2,2,3]
output: 2
另一个:
input[1,2,2,2,2,2,3,1,2,3]
output: 2
我的代码(无效):
int correctNumber= 1;
int occurrence= 0;
for (int i = 0; i < length; i++)
{
if (vector[i] > correctNumber){
correctNumber= 1;
if (vector[i] == correctNumber|| vector[i] == (correctNumber+ 1))
{
if (vector[i] == (correctNumber+ 1)){
correctNumber++;
}
if (vector[i] == 3 && vector[i + 1] != 3){
correctNumber= 1;
occurrences++;
}
}}
}