Skip to content

Commit fdf7819

Browse files
committed
solutions: 1550 - Three Consecutive Odds (Easy)
1 parent b335fa4 commit fdf7819

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
description: "Author: @wingkwong | https://leetcode.com/problems/three-consecutive-odds/"
3+
tags: [Array]
4+
---
5+
6+
# 1550 - Three Consecutive Odds (Easy)
7+
8+
## Problem Link
9+
10+
https://leetcode.com/problems/three-consecutive-odds/
11+
12+
## Problem Statement
13+
14+
Given an integer array `arr`, return `true` if there are three consecutive odd numbers in the array. Otherwise, return `false`.
15+
16+
**Example 1:**
17+
18+
```
19+
Input: arr = [2,6,4,1]
20+
Output: false
21+
Explanation: There are no three consecutive odds.
22+
```
23+
24+
**Example 2:**
25+
26+
```
27+
Input: arr = [1,2,34,3,4,5,7,23,12]
28+
Output: true
29+
Explanation: [5,7,23] are three consecutive odds.
30+
```
31+
32+
**Constraints:**
33+
34+
- `1 <= arr.length <= 1000`
35+
- `1 <= arr[i] <= 1000`
36+
37+
## Approach 1: TBC
38+
39+
<Tabs>
40+
<TabItem value="py" label="Python">
41+
<SolutionAuthor name="@wingkwong"/>
42+
43+
```py
44+
class Solution:
45+
def threeConsecutiveOdds(self, arr: List[int]) -> bool:
46+
for i in range(1, len(arr) - 1):
47+
if arr[i - 1] & 1 and arr[i] & 1 and arr[i + 1] & 1:
48+
return True
49+
return False
50+
```
51+
52+
</TabItem>
53+
</Tabs>

0 commit comments

Comments
 (0)