leetcode/solution/1500-1599/1550.Three Consecutive Odds/Solution.cpp

17 lines
335 B
C++

class Solution {
public:
bool threeConsecutiveOdds(vector<int>& arr) {
int cnt = 0;
for (int x : arr) {
if (x & 1) {
if (++cnt == 3) {
return true;
}
} else {
cnt = 0;
}
}
return false;
}
};