Skip to content

Commit 34bc22e

Browse files
Implement solution for max consecutive ones problem
1 parent 2e5b0ef commit 34bc22e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

485. Max Consecutive Ones.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int findMaxConsecutiveOnes(vector<int>& nums) {
4+
int max = 0;
5+
int count = 0;
6+
for(int i=0;i<nums.size();i++){
7+
if(nums[i]==1){
8+
count++;
9+
if(max<count){
10+
max = count;
11+
}
12+
}else{
13+
count = 0;
14+
}
15+
}
16+
return max;
17+
}
18+
};

0 commit comments

Comments
 (0)