Skip to content

Commit 9f83439

Browse files
authored
Merge pull request #921 from 0xff-dev/1550
Add solution and test-cases for problem 1550
2 parents 28aa316 + c209e37 commit 9f83439

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

leetcode/1501-1600/1550.Three-Consecutive-Odds/README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
# [1550.Three Consecutive Odds][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
4+
Given an integer array `arr`, return `true` if there are three consecutive odd numbers in the array. Otherwise, return `false`.
75

86
**Example 1:**
97

108
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
9+
Input: arr = [2,6,4,1]
10+
Output: false
11+
Explanation: There are no three consecutive odds.
1312
```
1413

15-
## 题意
16-
> ...
17-
18-
## 题解
14+
**Example 2:**
1915

20-
### 思路1
21-
> ...
22-
Three Consecutive Odds
23-
```go
2416
```
25-
17+
Input: arr = [1,2,34,3,4,5,7,23,12]
18+
Output: true
19+
Explanation: [5,7,23] are three consecutive odds.
20+
```
2621

2722
## 结语
2823

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(arr []int) bool {
4+
for i := 0; i < len(arr)-2; i++ {
5+
if arr[i]&1 == 1 && arr[i+1]&1 == 1 && arr[i+2]&1 == 1 {
6+
return true
7+
}
8+
}
9+
return false
510
}

leetcode/1501-1600/1550.Three-Consecutive-Odds/Solution_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
13+
inputs []int
1414
expect bool
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", []int{2, 4, 6, 1}, false},
17+
{"TestCase2", []int{1, 2, 34, 3, 4, 5, 7, 23, 12}, true},
1918
}
2019

2120
// 开始测试
@@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
3029
}
3130
}
3231

33-
// 压力测试
32+
// 压力测试
3433
func BenchmarkSolution(b *testing.B) {
3534
}
3635

37-
// 使用案列
36+
// 使用案列
3837
func ExampleSolution() {
3938
}

0 commit comments

Comments
 (0)