Max Consecutive Ones (Very Simple Solution)


  • 0
    C

    class Solution {
    public int findMaxConsecutiveOnes(int[] nums) {
    int count =0;
    int max=0;
    for(int i : nums)
    {
    if(i!=1)
    {
    count=0;
    }
    else
    {
    count++;
    }
    if (count>max)
    max=count;

        }
        return max;
    }
    

    }


Log in to reply
 

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