One pass / T : O(N), S : O(1)


  • 0
    J
    public class Solution {
        public int findMaxConsecutiveOnes(int[] nums) {
            int max = 0;
            int count = 0;
            for(int num : nums){
                if(num == 0){
                    max = Math.max(max, count);
                    count = 0;
                }
                else{
                    count++;
                }
            }
            max = Math.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.