문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
이진 배열 nums가 주어졌을 때, 배열에서 연속된 1의 최대 개수를 반환해라.
#1
Input: nums = [1, 1, 0, 1, 1, 1]
Output: 3
Explanation: 처음 두 자리와 마지막 세 자리가 연속된 1이다. 연속된 1의 최대 개수는 3개이다.
#2
Input: nums = [1, 0, 1, 1, 0, 1]
Output: 2
class Solution {
public int findMaxConsecutiveOnes(int[] nums) {
int maxCnt = 0;
int cnt = 0;
for(int i = 0; i < nums.length; i++){
if(nums[i] == 1){
cnt++;
maxCnt = Math.max(maxCnt, cnt);
}
else cnt = 0;
}
return maxCnt;
}
}