题目如下:

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: 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]

最新文章

  1. iOS UINavigationController(内容根据iOS编程编写)
  2. intellij中不能导入jar包
  3. oracle 函数
  4. 解决Mysql连接池被关闭 ,hibernate尝试连接不能连接的问题。 (默认mysql连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池。系统发布第二天访问链接关闭问题。
  5. CODEVS 3657 括号序列
  6. Android手机应用程序开发环境配置(Eclipse+Java+ADT)
  7. EMS-keil C51常用错误
  8. Android基于WIFI实现电脑和手机间数据传输的技术方案研究
  9. Android应用程序组件Content Provider的共享数据更新通知机制分析
  10. table之thead兼容
  11. Java开发中遇到的问题
  12. StackExchange.Redis学习笔记(三)
  13. 五个最佳RSS新闻阅读器
  14. canvas学习笔记,实用知识点总结(上)
  15. VSTO 获取sheet单元格行列数
  16. WebView内容自适应
  17. mysql权限操作(转)
  18. Confluence 6 编辑一个站点装饰文件
  19. 将表格导出为excel
  20. hive 解jason字符串

热门文章

  1. acm java入门(转载)
  2. LeetCode 141 ——环形链表(JAVA)
  3. Spring实战(八)bean装配的运行时值注入——属性占位符和SpEL
  4. C#面向对象12 集合
  5. 随便----js参考书
  6. ZROIDay4-比赛解题报告
  7. C++内存分配和分区
  8. HLSL中constant variables的packing规则
  9. java面试6
  10. KTV歌曲播放原理