Java easy to understand


  • 0
    G

    my code

    public class Solution {
        public int findMaxConsecutiveOnes(int[] nums) {
        int maxLen=0,all=0,ind=0;
        for(int i=0;i<nums.length;i++){
            all+=nums[i];
            if(all==ind+1){
                ind++;
                if(all>maxLen){maxLen=all;}
            }else{
                all=0;
                ind=0;}}
        return maxLen;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.