-
-
Notifications
You must be signed in to change notification settings - Fork 99
Closed
Labels
easyEasy level questionEasy level questionhacktoberest-acceptedhacktoberfest-acceptedhacktoberfest-acceptedhacktoberfesthacktoberfesthacktoberfest
Description
Problem Number
485
Problem Title
Max Consecutive Ones
LeetCode Link
https://leetcode.com/problems/max-consecutive-ones
Contribution Checklist
- I have written the Approach section.
- I have written the Intuition section.
- I have included a working C++ solution.
- I will raise a PR and ensure the filename follows the convention
[Number]. [Problem Title].cpp.
Approach
First I have to init
then iterate and then return
Intuition
have to find out the maximum consecutive once
Solution in C++
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int max = 0;
int count = 0;
for(int i=0;i<nums.size();i++){
if(nums[i]==1){
count++;
if(max<count){
max = count;
}
}else{
count = 0;
}
}
return max;
}
};Metadata
Metadata
Assignees
Labels
easyEasy level questionEasy level questionhacktoberest-acceptedhacktoberfest-acceptedhacktoberfest-acceptedhacktoberfesthacktoberfesthacktoberfest