1276.不浪费原料的汉堡制作方案
链接:1276.不浪费原料的汉堡制作方案
难度:Medium
标签:数学
简介:请你以 [total_jumbo, total_small]([巨无霸汉堡总数,小皇堡总数])的格式返回恰当的制作方案,使得剩下的番茄片 tomatoSlices 和奶酪片 cheeseSlices 的数量都是 0。
题解 1 - python
- 编辑时间:2023-12-25
- 执行用时:40ms
- 内存消耗:16.8MB
- 编程语言:python
- 解法介绍:二元一次方程。
class Solution:
def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:
# 4x + 2y = num1
# x + y = num2
# x = (num1 - 2num2) / 2
# y = num2 - x
x = (tomatoSlices - 2 * cheeseSlices) // 2
y = cheeseSlices - x
return [x, y] if x >= 0 and y >= 0 and 4 * x + 2 * y == tomatoSlices and x + y == cheeseSlices else []