본문 바로가기
Beakjoon&프로그래머스/Java

[LeetCode/Java] Max Consecutive Ones

by 현장 2025. 11. 24.

-Code

class Solution {
    public int findMaxConsecutiveOnes(int[] nums) {
        int answer = 0;
        int cnt = 0;
        
        for (int num : nums) {
            if (num == 1) {
                cnt++;
            } else {
                answer = Math.max(answer, cnt);
                cnt = 0;
            }
        }
        
        return Math.max(answer, cnt);
    }
}