跳至主要内容

1550. Three Consecutive Odds

class Solution {
public:
bool threeConsecutiveOdds(vector<int>& arr)
{
int cnt = 0;
for (int i = 0; i < arr.size(); i++)
{
if (arr[i] % 2) cnt++;
else cnt = 0;
if (cnt == 3) return true;
}
return false;
}
};
  • T: O(n)O(n)
  • S: O(1)O(1)