-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path485.cpp
42 lines (40 loc) · 883 Bytes
/
485.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
if(nums.size()==0)
return 0;
if(nums.size()==1&&nums[0]==1)
return 1;
if(nums.size()==1&&nums[0]==0)
return 0;
int ans=0;
int temp;
if(nums[0]==0)
temp=0;
if(nums[0]==1)
temp=1;
for(int i=1;i<nums.size();i++)
{
if (nums[i]==1)
{
temp++;
ans=max(ans,temp);
}
else if(nums[i]==0)
{
ans=max(temp,ans);
temp=0;
}
}
return ans;
}
};
int main() {
int a[6]={1,1,0,1,1,1};
vector<int> test(a,a+6);
Solution b;
cout<<b.findMaxConsecutiveOnes(test);
}