반응형
https://leetcode.com/problems/three-consecutive-odds
arr에서 3개의 연속된 수가 홀수인지 확인해줍니다.
class Solution {
public:
bool threeConsecutiveOdds(vector<int>& arr) {
int cnt = 0;
for(int i=0; i<arr.size(); i++) {
if(arr[i] % 2) {
if(++cnt == 3) return true;
} else {
cnt = 0;
}
}
return false;
}
};
반응형
'Algorithm' 카테고리의 다른 글
LeetCode 1310. XOR Queries of a Subarray (0) | 2025.02.09 |
---|---|
LeetCode 2364. Count Number of Bad Pairs (0) | 2025.02.09 |
LeetCode 350. Intersection of Two Arrays II (0) | 2024.07.06 |
LeetCode 2181. Merge Nodes in Between Zeros (0) | 2024.07.06 |
LeetCode 2582. Pass the Pillow (0) | 2024.07.06 |