力扣 485. 最大连续 1 的个数 难度:简单
题目地址: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;
}
}
本文来自博客园,作者:宗神一,转载请注明原文链接:https://www.cnblogs.com/zhangmuchen/p/15701802.html