#485 Max Consecutive Ones

题目:

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

if (tmp != tmp+nums[i]) {

tmp += nums[i];

} else {

ans = (ans>tmp)?ans:tmp;

tmp = 0;

}

}

return ans;

};

你可能感兴趣的:(#485 Max Consecutive Ones)