Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
```

## 结语

Expand Down
Original file line number Diff line number Diff line change
@@ -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}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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{}},
}

// 开始测试
Expand All @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading