Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int findMaxConsecutiveOnes(vector<int>& nums)
- {
- vector<int> vec; //vector define
- int i=0;
- while(i<nums.size())
- { //loop till whole input vector
- int j=0;
- while(i<nums.size() && nums[i]==1) // loop to count 1s
- {
- j++;
- i++;
- }
- vec.push_back(j); //vector to save no of continous 1
- i++;
- }
- // to return maximum in vec
- int max=vec[0]; //return *max_element(vec.begin(),vec.end());
- for(int i=0;i<vec.size();i++)
- {
- if(vec[i]>max)
- {
- max=vec[i];
- }
- }
- return max;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement