Java Simple Solution


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

Log in to reply
 

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