问题描述:Given a binary array, find the maximum number of consecutive 1s in this array.
Example1
Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.
class Solution {
public:int findMaxConsecutiveOnes(vector<int>& nums) {
int min=0;
vector<int>::iterator itr=nums.begin();
while(itr!=nums.end()) {
int a=0;
while(*itr!=0) {
if(itr==nums.end()) {
break;
}
a++;
itr++;
}
if(a>min) {
min=a;
}
if(itr==nums.end()) {
break;
}
itr++;
}
return min;
}
};
遍历判断0和1然后用if语句判断。