Skip to content

Add solution and test-cases for problem 2974 #1197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
30 changes: 16 additions & 14 deletions leetcode/2901-3000/2974.Minimum-Number-Game/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
# [2974.Minimum Number Game][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
You are given a **0-indexed** integer array `nums` of even length and there is also an empty array `arr`. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:

- Every round, first Alice will remove the **minimum** element from `nums`, and then Bob does the same.
- Now, first Bob will append the removed element in the array `arr`, and then Alice does the same.
- The game continues until `nums` becomes empty.

Return the resulting array `arr`.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: nums = [5,4,2,3]
Output: [3,2,5,4]
Explanation: In round one, first Alice removes 2 and then Bob removes 3. Then in arr firstly Bob appends 3 and then Alice appends 2. So arr = [3,2].
At the begining of round two, nums = [5,4]. Now, first Alice removes 4 and then Bob removes 5. Then both append in arr which becomes [3,2,5,4].
```

## 题意
> ...
**Example 2:**

## 题解

### 思路1
> ...
Minimum Number Game
```go
```

Input: nums = [2,5]
Output: [5,2]
Explanation: In round one, first Alice removes 2 and then Bob removes 5. Then in arr firstly Bob appends and then Alice appends. So arr = [5,2].
```

## 结语

Expand Down
12 changes: 10 additions & 2 deletions leetcode/2901-3000/2974.Minimum-Number-Game/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package Solution

func Solution(x bool) bool {
return x
import "sort"

func Solution(nums []int) []int {
sort.Ints(nums)
ans := make([]int, len(nums))
for i := 1; i < len(nums); i += 2 {
ans[i-1] = nums[i]
ans[i] = nums[i-1]
}
return ans
}
13 changes: 6 additions & 7 deletions leetcode/2901-3000/2974.Minimum-Number-Game/Solution_test.go
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 []int
expect []int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", []int{5, 4, 2, 3}, []int{3, 2, 5, 4}},
{"TestCase2", []int{2, 5}, []int{5, 2}},
}

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

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

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