题目地址:https://leetcode-cn.com/problems/max-consecutive-ones/
我的题解:
class Solution { public int findMaxConsecutiveOnes(int[] nums) { int max = 0; int curMax = 0; for(int i=0;i<nums.length;i++){ if(nums[i]==1){ curMax +=1; if(i==nums.length-1){ if(curMax>max){ max = curMax; } } }else{ if(curMax>max){ max = curMax; } //当前连续输清零 curMax = 0; } } return max; } }