Skip to content

Commit 9b2c73e

Browse files
authored
Merge pull request #1267 from 0xff-dev/2413
Add solution and test-cases for problem 2413
2 parents d2b994e + ec0f38a commit 9b2c73e

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

leetcode/2401-2500/2413.Smallest-Even-Multiple/README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
# [2413.Smallest Even Multiple][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 a **positive** integer `n`, return the smallest positive integer that is a multiple of **both** `2` and `n`.
75

86
**Example 1:**
97

108
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
9+
Input: n = 5
10+
Output: 10
11+
Explanation: The smallest multiple of both 5 and 2 is 10.
1312
```
1413

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

20-
### 思路1
21-
> ...
22-
Smallest Even Multiple
23-
```go
2416
```
25-
17+
Input: n = 6
18+
Output: 6
19+
Explanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multiple of itself.
20+
```
2621

2722
## 结语
2823

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

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(n int) int {
4+
if n&1 == 1 {
5+
return 2 * n
6+
}
7+
return n
58
}

leetcode/2401-2500/2413.Smallest-Even-Multiple/Solution_test.go

Lines changed: 6 additions & 7 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
14-
expect bool
13+
inputs int
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", 5, 10},
17+
{"TestCase2", 6, 6},
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)