Max Consecutive Ones LeetCode solution in Java
1class Solution {2public int findMaxConsecutiveOnes(int[] nums) {3int max = 0;4int new_max = 0;5for (int i = 0; i < nums.length; i++) {6if (nums[i] == 1) {7max++;8} else {9if (max > new_max) {10new_max = max;11}12max = 0;13}14}15if (max < new_max) return new_max;16else return max;17}18}