Skip to content

Commit 104c80f

Browse files
committed
Sync LeetCode submission Runtime - 0 ms (100.00%), Memory - 17.9 MB (38.15%)
1 parent f9dac0f commit 104c80f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Given an integer array <code>arr</code>, return <code>true</code>&nbsp;if there are three consecutive odd numbers in the array. Otherwise, return&nbsp;<code>false</code>.
2+
<p>&nbsp;</p>
3+
<p><strong class="example">Example 1:</strong></p>
4+
5+
<pre>
6+
<strong>Input:</strong> arr = [2,6,4,1]
7+
<strong>Output:</strong> false
8+
<b>Explanation:</b> There are no three consecutive odds.
9+
</pre>
10+
11+
<p><strong class="example">Example 2:</strong></p>
12+
13+
<pre>
14+
<strong>Input:</strong> arr = [1,2,34,3,4,5,7,23,12]
15+
<strong>Output:</strong> true
16+
<b>Explanation:</b> [5,7,23] are three consecutive odds.
17+
</pre>
18+
19+
<p>&nbsp;</p>
20+
<p><strong>Constraints:</strong></p>
21+
22+
<ul>
23+
<li><code>1 &lt;= arr.length &lt;= 1000</code></li>
24+
<li><code>1 &lt;= arr[i] &lt;= 1000</code></li>
25+
</ul>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Approach 2: Counting
2+
3+
# Time: O(n)
4+
# Space: O(1)
5+
6+
class Solution:
7+
def threeConsecutiveOdds(self, arr: List[int]) -> bool:
8+
cons_odds = 0
9+
10+
for num in arr:
11+
if num % 2 == 1:
12+
cons_odds += 1
13+
else:
14+
cons_odds = 0
15+
16+
if cons_odds == 3:
17+
return True
18+
19+
return False
20+

0 commit comments

Comments
 (0)