public static Integer counts(List<Integer> list){
// Inter数组
// int[] x = {1, 2, 1, 1, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1};
// 之前的整数
int beforeNumber = list.get(0);
// 当前连续计数
int currCount = 1;
// 最大连续计数
int maxCount = 1;
// 最大连续出现次数的整数
int maxContinuousNumber = 0;
for(int i=1; i < list.size(); ++i) {
if(beforeNumber == list.get(i)) {
++currCount;
} else {
// System.out.println(beforeNumber + "\t连续出现次数: " + currCount);
currCount = 1;
}
// 判断当前连续计数是否大于最大连续计数,如果是则重新赋值
if(currCount > maxCount) {
maxCount = currCount;
maxContinuousNumber = beforeNumber;
}
beforeNumber = list.get(i);
}
if (maxContinuousNumber == 1 && maxCount >= 3){
return maxCount;
} else {
return 0;
}
}