easy java solution


  • 0
    L
    public int findMaxConsecutiveOnes(int[] nums) {
    	int ones=0, max=0;
    	for(int i=0; i<nums.length; i++) {
    		ones=nums[i]==1?ones+1:0;
    		max=max<ones?ones:max;
    	}
    	return max;
    }

Log in to reply
 

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