
-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);
}
}
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [LeetCode/Java] How Many Numbers Are Smaller Than the Current Number (0) | 2025.11.24 |
|---|---|
| [LeetCode/Java] Set Mismatch (0) | 2025.11.24 |
| [LeetCode/Java] Shuffle the Array (0) | 2025.11.24 |
| [LeetCode/Java] Concatenation of Array (0) | 2025.11.24 |
| [LeetCode/Java] 94. Binary Tree Inorder Traversal (0) | 2025.11.23 |