其他分享
首页 > 其他分享> > 力扣 485. 最大连续 1 的个数 难度:简单

力扣 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;     } }

标签:cn,int,max,curMax,个数,力扣,题解,485,清零
来源: https://www.cnblogs.com/zhangmuchen/p/15701802.html