package leetcode;

/**
 * https://leetcode.com/problems/max-consecutive-ones/
 */
public class Problem485 {
    public int findMaxConsecutiveOnes(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem485 prob = new Problem485();
        System.out.println(prob.findMaxConsecutiveOnes(new int[]{1, 1, 0, 1, 1, 1})); // 3
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/max-consecutive-ones/
 */
public class Problem485 {
    public int findMaxConsecutiveOnes(int[] nums) {
        int max = 0;
        int tmpMax = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 1) {
                tmpMax++;
            } else {
                tmpMax = 0;
            }
            max = Math.max(max, tmpMax);
        }
        return max;
    }
}

Solve problem 485