首页 > 其他 > 详细

leetcode1276

时间:2019-12-01 13:40:45      阅读:97      评论:0      收藏:0      [点我收藏+]
 1 class Solution:
 2     def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:
 3         tomato_low = cheeseSlices * 2
 4         tomato_high = cheeseSlices * 4
 5         if tomatoSlices % 2 == 1 or tomatoSlices < tomato_low or tomatoSlices > tomato_high:
 6             return []
 7         div1,res1 = (tomatoSlices - tomato_low) // 2,(tomatoSlices - tomato_low) % 2
 8         if res1 == 0:
 9             return [div1,cheeseSlices-div1]
10         return []

以 cheese为基础,
假设全部都是 小的,则需要 2 * cheese 个tomato,记为 tomato_low
假设全部都是 大的,则需要 4 * cheese 个tomato,记为 tomato_high

先判断提供的tomato是否在这个区间内,
如果不在这个区间内,则返回[]在这个区间内。

本题实际是要在这个区间内,看是否能够查询到tomato。

tomato_low与tomato_high都是偶数,如果tomato在[low,high]之间,并且也是偶数,则肯定能够满足条件。

只需计算,tomato与low的商,就表示需要做几个huge型的汉堡,而high - tomato,就是small型汉堡的数量。

leetcode1276

原文:https://www.cnblogs.com/asenyang/p/11965571.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!