From ec0f38a51eb44e4b22b1e8011221b998e55a6a46 Mon Sep 17 00:00:00 2001 From: 0xff-dev Date: Tue, 22 Jul 2025 09:15:18 +0800 Subject: [PATCH] Add solution and test-cases for problem 2413 --- .../2413.Smallest-Even-Multiple/README.md | 23 ++++++++----------- .../2413.Smallest-Even-Multiple/Solution.go | 7 ++++-- .../Solution_test.go | 13 +++++------ 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/leetcode/2401-2500/2413.Smallest-Even-Multiple/README.md b/leetcode/2401-2500/2413.Smallest-Even-Multiple/README.md index c16d14f57..f0541420f 100755 --- a/leetcode/2401-2500/2413.Smallest-Even-Multiple/README.md +++ b/leetcode/2401-2500/2413.Smallest-Even-Multiple/README.md @@ -1,28 +1,23 @@ # [2413.Smallest Even Multiple][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 a **positive** integer `n`, return the smallest positive integer that is a multiple of **both** `2` and `n`. **Example 1:** ``` -Input: a = "11", b = "1" -Output: "100" +Input: n = 5 +Output: 10 +Explanation: The smallest multiple of both 5 and 2 is 10. ``` -## 题意 -> ... - -## 题解 +**Example 2:** -### 思路1 -> ... -Smallest Even Multiple -```go ``` - +Input: n = 6 +Output: 6 +Explanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multiple of itself. +``` ## 结语 diff --git a/leetcode/2401-2500/2413.Smallest-Even-Multiple/Solution.go b/leetcode/2401-2500/2413.Smallest-Even-Multiple/Solution.go index d115ccf5e..ba225bb4f 100644 --- a/leetcode/2401-2500/2413.Smallest-Even-Multiple/Solution.go +++ b/leetcode/2401-2500/2413.Smallest-Even-Multiple/Solution.go @@ -1,5 +1,8 @@ package Solution -func Solution(x bool) bool { - return x +func Solution(n int) int { + if n&1 == 1 { + return 2 * n + } + return n } diff --git a/leetcode/2401-2500/2413.Smallest-Even-Multiple/Solution_test.go b/leetcode/2401-2500/2413.Smallest-Even-Multiple/Solution_test.go index 14ff50eb4..13ba7368d 100644 --- a/leetcode/2401-2500/2413.Smallest-Even-Multiple/Solution_test.go +++ b/leetcode/2401-2500/2413.Smallest-Even-Multiple/Solution_test.go @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) { // 测试用例 cases := []struct { name string - inputs bool - expect bool + inputs int + expect int }{ - {"TestCase", true, true}, - {"TestCase", true, true}, - {"TestCase", false, false}, + {"TestCase1", 5, 10}, + {"TestCase2", 6, 6}, } // 开始测试 @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) { } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }