From 7ff16bb8760427e20277060a83f4b42a52527351 Mon Sep 17 00:00:00 2001 From: 0xff-dev Date: Sat, 19 Apr 2025 20:21:52 +0800 Subject: [PATCH] Add solution and test-cases for problem 1276 --- .../README.md | 35 ++++++++++++------- .../Solution.go | 15 ++++++-- .../Solution_test.go | 22 ++++++------ 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/README.md b/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/README.md index 3b7526141..d13d0c5a3 100644 --- a/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/README.md +++ b/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/README.md @@ -1,28 +1,37 @@ # [1276.Number of Burgers with No Waste of Ingredients][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 two integers `tomatoSlices` and `cheeseSlices`. The ingredients of different burgers are as follows: + +- **Jumbo Burger**: `4` tomato slices and `1` cheese slice. +- **Small Burger**: `2` Tomato slices and `1` cheese slice. + +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 `[]`. **Example 1:** ``` -Input: a = "11", b = "1" -Output: "100" +Input: tomatoSlices = 16, cheeseSlices = 7 +Output: [1,6] +Explantion: To make one jumbo burger and 6 small burgers we need 4*1 + 2*6 = 16 tomato and 1 + 6 = 7 cheese. +There will be no remaining ingredients. ``` -## 题意 -> ... - -## 题解 +**Example 2:** -### 思路1 -> ... -Number of Burgers with No Waste of Ingredients -```go ``` +Input: tomatoSlices = 17, cheeseSlices = 4 +Output: [] +Explantion: There will be no way to use all ingredients to make small and jumbo burgers. +``` + +**Example 3:** +``` +Input: tomatoSlices = 4, cheeseSlices = 17 +Output: [] +Explantion: Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining. +``` ## 结语 diff --git a/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/Solution.go b/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/Solution.go index d115ccf5e..434cd0891 100644 --- a/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/Solution.go +++ b/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/Solution.go @@ -1,5 +1,16 @@ package Solution -func Solution(x bool) bool { - return x +func Solution(tomatoSlices int, cheeseSlices int) []int { + // 4x + 2y = tomatoSlices + // 2x + 2y = 2*cheeseSlices + jumbo := tomatoSlices - 2*cheeseSlices + if jumbo < 0 || jumbo&1 == 1 { + return []int{} + } + a := jumbo / 2 + b := cheeseSlices - a + if b < 0 { + return []int{} + } + return []int{a, b} } diff --git a/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/Solution_test.go b/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/Solution_test.go index 14ff50eb4..7372844b3 100644 --- a/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/Solution_test.go +++ b/leetcode/1201-1300/1276.Number-of-Burgers-with-No-Waste-of-Ingredients/Solution_test.go @@ -9,31 +9,31 @@ import ( func TestSolution(t *testing.T) { // 测试用例 cases := []struct { - name string - inputs bool - expect bool + name string + tomatoSlices, cheeseSlices int + expect []int }{ - {"TestCase", true, true}, - {"TestCase", true, true}, - {"TestCase", false, false}, + {"TestCase1", 16, 7, []int{1, 6}}, + {"TestCase2", 17, 4, []int{}}, + {"TestCase3", 4, 17, []int{}}, } // 开始测试 for i, c := range cases { t.Run(c.name+" "+strconv.Itoa(i), func(t *testing.T) { - got := Solution(c.inputs) + got := Solution(c.tomatoSlices, c.cheeseSlices) if !reflect.DeepEqual(got, c.expect) { - t.Fatalf("expected: %v, but got: %v, with inputs: %v", - c.expect, got, c.inputs) + t.Fatalf("expected: %v, but got: %v, with inputs: %v %v", + c.expect, got, c.tomatoSlices, c.cheeseSlices) } }) } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }