From c209e37a6cfeaad578c71ba6ac93b6e9d51d5fca Mon Sep 17 00:00:00 2001 From: 0xff-dev Date: Mon, 1 Jul 2024 08:53:13 +0800 Subject: [PATCH] Add solution and test-cases for problem 1550 --- .../1550.Three-Consecutive-Odds/README.md | 23 ++++++++----------- .../1550.Three-Consecutive-Odds/Solution.go | 9 ++++++-- .../Solution_test.go | 11 ++++----- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/leetcode/1501-1600/1550.Three-Consecutive-Odds/README.md b/leetcode/1501-1600/1550.Three-Consecutive-Odds/README.md index 2ec667b98..0e1372031 100755 --- a/leetcode/1501-1600/1550.Three-Consecutive-Odds/README.md +++ b/leetcode/1501-1600/1550.Three-Consecutive-Odds/README.md @@ -1,28 +1,23 @@ # [1550.Three Consecutive Odds][title] -> [!WARNING|style:flat] -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) - ## Description +Given an integer array `arr`, return `true` if there are three consecutive odd numbers in the array. Otherwise, return `false`. **Example 1:** ``` -Input: a = "11", b = "1" -Output: "100" +Input: arr = [2,6,4,1] +Output: false +Explanation: There are no three consecutive odds. ``` -## 题意 -> ... - -## 题解 +**Example 2:** -### 思路1 -> ... -Three Consecutive Odds -```go ``` - +Input: arr = [1,2,34,3,4,5,7,23,12] +Output: true +Explanation: [5,7,23] are three consecutive odds. +``` ## 结语 diff --git a/leetcode/1501-1600/1550.Three-Consecutive-Odds/Solution.go b/leetcode/1501-1600/1550.Three-Consecutive-Odds/Solution.go index d115ccf5e..4ba32422a 100644 --- a/leetcode/1501-1600/1550.Three-Consecutive-Odds/Solution.go +++ b/leetcode/1501-1600/1550.Three-Consecutive-Odds/Solution.go @@ -1,5 +1,10 @@ package Solution -func Solution(x bool) bool { - return x +func Solution(arr []int) bool { + for i := 0; i < len(arr)-2; i++ { + if arr[i]&1 == 1 && arr[i+1]&1 == 1 && arr[i+2]&1 == 1 { + return true + } + } + return false } diff --git a/leetcode/1501-1600/1550.Three-Consecutive-Odds/Solution_test.go b/leetcode/1501-1600/1550.Three-Consecutive-Odds/Solution_test.go index 14ff50eb4..d1eb74050 100644 --- a/leetcode/1501-1600/1550.Three-Consecutive-Odds/Solution_test.go +++ b/leetcode/1501-1600/1550.Three-Consecutive-Odds/Solution_test.go @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) { // 测试用例 cases := []struct { name string - inputs bool + inputs []int expect bool }{ - {"TestCase", true, true}, - {"TestCase", true, true}, - {"TestCase", false, false}, + {"TestCase1", []int{2, 4, 6, 1}, false}, + {"TestCase2", []int{1, 2, 34, 3, 4, 5, 7, 23, 12}, true}, } // 开始测试 @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) { } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }