Skip to content

Commit 06886f3

Browse files
authored
Merge pull request #1455 from 0xff-dev/1753
Add solution and test-cases for problem 1753
2 parents c8d2d70 + 5c98cfe commit 06886f3

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

leetcode/1701-1800/1753.Maximum-Score-From-Removing-Stones/README.md

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
11
# [1753.Maximum Score From Removing Stones][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+
You are playing a solitaire game with **three piles** of stones of sizes `a`, `b`, `c` respectively. Each turn you choose two **different non-empty** piles, take one stone from each, and add `1` point to your score. The game stops when there are **fewer than two non-empty** piles (meaning there are no more available moves).
5+
6+
Given three integers `a`, `b`, and `c` return the **maximum score** you can get.
77

88
**Example 1:**
99

1010
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
11+
Input: a = 2, b = 4, c = 6
12+
Output: 6
13+
Explanation: The starting state is (2, 4, 6). One optimal set of moves is:
14+
- Take from 1st and 3rd piles, state is now (1, 4, 5)
15+
- Take from 1st and 3rd piles, state is now (0, 4, 4)
16+
- Take from 2nd and 3rd piles, state is now (0, 3, 3)
17+
- Take from 2nd and 3rd piles, state is now (0, 2, 2)
18+
- Take from 2nd and 3rd piles, state is now (0, 1, 1)
19+
- Take from 2nd and 3rd piles, state is now (0, 0, 0)
20+
There are fewer than two non-empty piles, so the game ends. Total: 6 points.
1321
```
1422

15-
## 题意
16-
> ...
23+
**Example 2:**
1724

18-
## 题解
19-
20-
### 思路1
21-
> ...
22-
Maximum Score From Removing Stones
23-
```go
25+
```
26+
Input: a = 4, b = 4, c = 6
27+
Output: 7
28+
Explanation: The starting state is (4, 4, 6). One optimal set of moves is:
29+
- Take from 1st and 2nd piles, state is now (3, 3, 6)
30+
- Take from 1st and 3rd piles, state is now (2, 3, 5)
31+
- Take from 1st and 3rd piles, state is now (1, 3, 4)
32+
- Take from 1st and 3rd piles, state is now (0, 3, 3)
33+
- Take from 2nd and 3rd piles, state is now (0, 2, 2)
34+
- Take from 2nd and 3rd piles, state is now (0, 1, 1)
35+
- Take from 2nd and 3rd piles, state is now (0, 0, 0)
36+
There are fewer than two non-empty piles, so the game ends. Total: 7 points.
2437
```
2538

39+
**Example 3:**
40+
41+
```
42+
Input: a = 1, b = 8, c = 8
43+
Output: 8
44+
Explanation: One optimal set of moves is to take from the 2nd and 3rd piles for 8 turns until they are empty.
45+
After that, there are fewer than two non-empty piles, so the game ends.
46+
```
2647

2748
## 结语
2849

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

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(a int, b int, c int) int {
4+
total := a + b + c
5+
max_heap := max(a, b, c)
6+
return min(total/2, total-max_heap)
57
}

leetcode/1701-1800/1753.Maximum-Score-From-Removing-Stones/Solution_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ import (
99
func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
12-
name string
13-
inputs bool
14-
expect bool
12+
name string
13+
a, b, c int
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", 2, 4, 6, 6},
17+
{"TestCase2", 4, 4, 6, 7},
18+
{"TestCase3", 1, 8, 8, 8},
1919
}
2020

2121
// 开始测试
2222
for i, c := range cases {
2323
t.Run(c.name+" "+strconv.Itoa(i), func(t *testing.T) {
24-
got := Solution(c.inputs)
24+
got := Solution(c.a, c.b, c.c)
2525
if !reflect.DeepEqual(got, c.expect) {
26-
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
27-
c.expect, got, c.inputs)
26+
t.Fatalf("expected: %v, but got: %v, with inputs: %v %v %v",
27+
c.expect, got, c.a, c.b, c.c)
2828
}
2929
})
3030
}
3131
}
3232

33-
// 压力测试
33+
// 压力测试
3434
func BenchmarkSolution(b *testing.B) {
3535
}
3636

37-
// 使用案列
37+
// 使用案列
3838
func ExampleSolution() {
3939
}

0 commit comments

Comments
 (0)