Skip to content

Commit 0f24fe6

Browse files
authored
Merge pull request #1180 from 0xff-dev/1276
Add solution and test-cases for problem 1276
2 parents c7bdacc + 7ff16bb commit 0f24fe6

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
# [1276.Number of Burgers with No Waste of Ingredients][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 two integers `tomatoSlices` and `cheeseSlices`. The ingredients of different burgers are as follows:
5+
6+
- **Jumbo Burger**: `4` tomato slices and `1` cheese slice.
7+
- **Small Burger**: `2` Tomato slices and `1` cheese slice.
8+
9+
Return `[total_jumbo, total_small]` so that the number of remaining `tomatoslices` equal to `0` and the number of remaining `cheeseSlices` equal to `0`. If it is not possible to make the remaining `tomatoSlices` and `cheeseSlices` equal to `0` return `[]`.
710

811
**Example 1:**
912

1013
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
14+
Input: tomatoSlices = 16, cheeseSlices = 7
15+
Output: [1,6]
16+
Explantion: To make one jumbo burger and 6 small burgers we need 4*1 + 2*6 = 16 tomato and 1 + 6 = 7 cheese.
17+
There will be no remaining ingredients.
1318
```
1419

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

20-
### 思路1
21-
> ...
22-
Number of Burgers with No Waste of Ingredients
23-
```go
2422
```
23+
Input: tomatoSlices = 17, cheeseSlices = 4
24+
Output: []
25+
Explantion: There will be no way to use all ingredients to make small and jumbo burgers.
26+
```
27+
28+
**Example 3:**
2529

30+
```
31+
Input: tomatoSlices = 4, cheeseSlices = 17
32+
Output: []
33+
Explantion: Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining.
34+
```
2635

2736
## 结语
2837

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

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(tomatoSlices int, cheeseSlices int) []int {
4+
// 4x + 2y = tomatoSlices
5+
// 2x + 2y = 2*cheeseSlices
6+
jumbo := tomatoSlices - 2*cheeseSlices
7+
if jumbo < 0 || jumbo&1 == 1 {
8+
return []int{}
9+
}
10+
a := jumbo / 2
11+
b := cheeseSlices - a
12+
if b < 0 {
13+
return []int{}
14+
}
15+
return []int{a, b}
516
}

leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/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+
tomatoSlices, cheeseSlices int
14+
expect []int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", 16, 7, []int{1, 6}},
17+
{"TestCase2", 17, 4, []int{}},
18+
{"TestCase3", 4, 17, []int{}},
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.tomatoSlices, c.cheeseSlices)
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",
27+
c.expect, got, c.tomatoSlices, c.cheeseSlices)
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)