easy java solution


  • 0
    S

    easy java solution

    public class Solution {
        public int findMaxConsecutiveOnes(int[] nums) {
            int max = 0;
            int index = -1;
            int len = nums.length;
            for(int i=0; i<len; i++){
                if(nums[i] == 1)
                    max = (max>(i - index))?max:(i - index);
                else
                    index = i;
            }
            
            return max;
        }
    }
    

Log in to reply
 

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