Leetcode学习笔记:#485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.
实现
public int findMaxConsecutiveOnes(int[] nums){
int maxHere = 0, max = 0;
for(int n : nums)
max = Math.max(max, maxHere = n == 0 ? 0 : maxHere + 1);
return max;
思路:
用一个maxHere保存最大值,与现在的最大值做比较即可