线性枚举,就是对数组进行操作,一般是对数组进行遍历,所以最坏时间复杂度为O(n)
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int len = nums.size();
int temp = 0,max = 0;
for(int i = 0;i<len;++i){
if(nums[i] == 1){
++temp;
if(temp>max) max = temp;
}
else{
temp = 0;
}
}
return max;
}
};