문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
정수 배열 arr이 주어졌을 때, 배열에 연속된 홀수가 3개 있으면 true를 반환해라. 그렇지 않다면 false를 반환해라.
#1
Input: arr = [2, 6, 4, 1]
Output: false
Explanation: 연속된 홀수 3개가 없다.
#2
Input: arr = [1, 2, 34, 3, 4, 5, 7, 23, 12]
Output: true
Explanation: [5, 7, 23]은 연속된 홀수 3개이다.
class Solution {
public boolean threeConsecutiveOdds(int[] arr) {
int count = 0;
for(int i : arr){
if(i % 2 == 1){
count++;
}else{
count = 0;
}
if(count == 3){
return true;
}
}
return false;
}
}