题目:
Given a binary array, find the maximum number of consecutive 1s in this array.
代码:
var findMaxConsecutiveOnes = function(nums) {
let ans = 0, tmp = 0, len = nums.length;
nums[len] = 0;
for(let i=0;i<len+1;++i){
if (tmp != tmp+nums[i]) {
tmp += nums[i];
} else {
ans = (ans>tmp)?ans:tmp;
tmp = 0;
}
}
return ans;
};
网友评论