Intuitive Java Solution


  • 0
    S
    
    class Solution
    {
        public int findMaxConsecutiveOnes(int[] nums) 
        {
           int count=0;
           int max=0;
           for(int i=0;i<nums.length;i++)
           {
        	   if(nums[i]==1)
        	   {
        		   count++;
        		   max=Math.max(max,count);
        	   }
        	   else
        	   {
        		   if(count!=0)
        			   count=0;
        	   }
           }
           return max;
        }
    }
    

Log in to reply
 

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