485
[思路]:
寻找0.1序列中连续为1的子序列的长度;
- 遍历一次,统计;
int findMaxConsecutiveOnes(vector<int>& nums) {
int maxc = 0, cnt = 0;
for(auto &num:nums){
if(num == 1) cnt++;
else cnt=0;
maxc = max(maxc, cnt);
}
return maxc;
}
网友评论