clueless coding // TODO: be smarter

LeetCode Max Consecutive Ones: Java Solution



TL;DR Code Solution


public int findMaxConsecutiveOnes(int[] nums) {

    int max = 0;
    int curr = 0;
    for (int val : nums) {
        if (val == 1) {
            curr += 1;
            max = Math.max(max, curr);
        }
        else {
            curr = 0;
        }
    }
    return max;

}