package com.sitech.iot.monitor.controller;
public class mian {
public static int findMaxConsecutiveOnes(int[] nums) {
int max = 0;
int tempMax = 0;
for(int i = 0; i < nums.length; i++){
if(nums[i] == 1){
tempMax++;
} else if(tempMax != 0){
max = Math.max(max, tempMax);
tempMax = 0;
}
}
// 数组最后一个数字为1时,最后的tempMax和max没有进行比较, 所以循环结束再比较一次
max = Math.max(max, tempMax);
return max;
}
public static void main (String args[]){
int [] i={0,1,0,1,1,1,1};
int ss= findMaxConsecutiveOnes(i);
System.out.println(ss);
}
}