【leetcode】1276. Number of Burgers with No Waste of Ingredients
2024-10-06 20:23:57
题目如下:
Given two integers
tomatoSlices
andcheeseSlices
. 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 remainingtomatoSlices
equal to 0 and the number of remainingcheeseSlices
equal to 0. If it is not possible to make the remainingtomatoSlices
andcheeseSlices
equal to 0 return[]
.Example 1:
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:
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.Example 4:
Input: tomatoSlices = 0, cheeseSlices = 0
Output: [0,0]Example 5:
Input: tomatoSlices = 2, cheeseSlices = 1
Output: [0,1]Constraints:
0 <= tomatoSlices <= 10^7
0 <= cheeseSlices <= 10^7
解题思路:解二元一次方程。
代码如下:
class Solution(object):
def numOfBurgers(self, tomatoSlices, cheeseSlices):
"""
:type tomatoSlices: int
:type cheeseSlices: int
:rtype: List[int]
"""
if (tomatoSlices - 2*cheeseSlices)%2 != 0 or (4*cheeseSlices - tomatoSlices) % 2 != 0:
return []
elif (tomatoSlices - 2*cheeseSlices)/2 < 0 or (4*cheeseSlices - tomatoSlices) / 2 < 0:
return []
return [(tomatoSlices - 2*cheeseSlices)/2, (4*cheeseSlices - tomatoSlices) / 2]
最新文章
- iOS UINavigationController(内容根据iOS编程编写)
- intellij中不能导入jar包
- oracle 函数
- 解决Mysql连接池被关闭 ,hibernate尝试连接不能连接的问题。 (默认mysql连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池。系统发布第二天访问链接关闭问题。
- CODEVS 3657 括号序列
- Android手机应用程序开发环境配置(Eclipse+Java+ADT)
- EMS-keil C51常用错误
- Android基于WIFI实现电脑和手机间数据传输的技术方案研究
- Android应用程序组件Content Provider的共享数据更新通知机制分析
- table之thead兼容
- Java开发中遇到的问题
- StackExchange.Redis学习笔记(三)
- 五个最佳RSS新闻阅读器
- canvas学习笔记,实用知识点总结(上)
- VSTO 获取sheet单元格行列数
- WebView内容自适应
- mysql权限操作(转)
- Confluence 6 编辑一个站点装饰文件
- 将表格导出为excel
- hive 解jason字符串