Java O(n) time O(1) Space


  • 0
    public int findMaxConsecutiveOnes(int[] A) {
        int maxCount = 0, count = 0;
        for (int i=0;i<A.length;i++) {
            count = A[i] == 0 ? 0 : count+1;
            maxCount = Math.max(maxCount, count);
        }
        return maxCount;
    }
    

Log in to reply
 

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