diff --git a/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/README.md b/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/README.md index 71b2fe39c..c7b64dca9 100755 --- a/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/README.md +++ b/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/README.md @@ -1,28 +1,24 @@ # [2177.Find Three Consecutive Integers That Sum to a Given Number][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 `num`, return three consecutive integers (as a sorted array) that **sum** to `num`. If `num` cannot be expressed as the sum of three consecutive integers, return an **empty** array. **Example 1:** ``` -Input: a = "11", b = "1" -Output: "100" +Input: num = 33 +Output: [10,11,12] +Explanation: 33 can be expressed as 10 + 11 + 12 = 33. +10, 11, 12 are 3 consecutive integers, so we return [10, 11, 12]. ``` -## 题意 -> ... - -## 题解 +**Example 2:** -### 思路1 -> ... -Find Three Consecutive Integers That Sum to a Given Number -```go ``` - +Input: num = 4 +Output: [] +Explanation: There is no way to express 4 as the sum of 3 consecutive integers. +``` ## 结语 diff --git a/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/Solution.go b/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/Solution.go index d115ccf5e..f59ff56da 100644 --- a/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/Solution.go +++ b/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/Solution.go @@ -1,5 +1,9 @@ package Solution -func Solution(x bool) bool { - return x +func Solution(num int64) []int64 { + if num%3 != 0 { + return []int64{} + } + mid := num / 3 + return []int64{mid - 1, mid, mid + 1} } diff --git a/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/Solution_test.go b/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/Solution_test.go index 14ff50eb4..7370ab829 100644 --- a/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/Solution_test.go +++ b/leetcode/2101-2200/2177.Find-Three-Consecutive-Integers-That-Sum-to-a-Given-Number/Solution_test.go @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) { // 测试用例 cases := []struct { name string - inputs bool - expect bool + inputs int64 + expect []int64 }{ - {"TestCase", true, true}, - {"TestCase", true, true}, - {"TestCase", false, false}, + {"TestCase1", 33, []int64{10, 11, 12}}, + {"TestCase2", 4, []int64{}}, } // 开始测试 @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) { } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }