My Java Solution


  • 0
    L

    public class Solution {

    public int findMaxConsecutiveOnes(int[] nums) { 
        int maxLen = 0;
        int currLen = 0;
        for (int num : nums) {
            if(num == 0){
                if(currLen > maxLen){
                    maxLen = currLen;
                }
                currLen = 0;
            }else{
                currLen ++;
            }
        }
        
        if(currLen > maxLen){
            maxLen = currLen;
        }
        
        return maxLen;
    }
    

    }


Log in to reply
 

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