lurenaa的博客

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int max1 = 0;
int k = 0;
for(auto x: nums) {
if(x == 1) {
++k;
} else {

k = 0;
}
max1 = max(max1, k);
}
return max1;
}
};

Accepted

41/41 cases passed (40 ms)

Your runtime beats 41.04 % of cpp submissions

Your memory usage beats 54.84 % of cpp submissions (11.7 MB)