Skip to content

Commit 0b6145d

Browse files
authored
Create three-consecutive-odds.cpp
1 parent 278e098 commit 0b6145d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

C++/three-consecutive-odds.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
bool threeConsecutiveOdds(vector<int>& arr) {
7+
int count = 0;
8+
for (const auto& x : arr) {
9+
count = x % 2 ? count + 1 : 0;
10+
if (count == 3) {
11+
return true;
12+
}
13+
}
14+
return false;
15+
}
16+
};

0 commit comments

Comments
 (0)