https://leetcode.com/problems/max-consecutive-ones/
Given a binary array nums, return the maximum number of consecutive 1's in the array.
연속된 1의 최대 개수를 리턴
class Solution {
public int findMaxConsecutiveOnes(int[] nums) {
int cnt = 0;
int max = 0;
for(int i : nums){
if(i == 1){
cnt++;
if(cnt > max){
max = cnt;
}
} else {
cnt = 0;
}
}
return max;
}
}
1이 나오면 cnt의 개수를 올리고, 0이 나오면 cnt를 0으로 초기화
max에 cnt의 최대값을 넣고 리턴