Skip to content

Commit c6edffe

Browse files
authored
Create 21_maxConsecutiveOnes.cpp
1 parent a0ce9e6 commit c6edffe

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
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 total = 0;
5+
int res = 0;
6+
7+
for(auto n : nums) {
8+
if(n) {
9+
total++;
10+
res = max(res, total);
11+
} else {
12+
total = 0;
13+
}
14+
}
15+
16+
return res;
17+
}
18+
};

0 commit comments

Comments
 (0)