Simple Java Solution


  • 0
    C

    ''' public class Solution {
    public int findMaxConsecutiveOnes(int[] nums) {
    int count = 0;
    int history = 0;
    for (int i = 0; i< nums.length; i++)
    {
    if(nums[i] == 1)
    {
    count++;
    }
    else
    {
    if( history == 0 || history < count)
    {
    history = count;
    }
    count =0;
    }
    }

        if(history < count)
        {
            return count;
        }
        return history;
    }
    

    }
    '''


Log in to reply
 

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