leetcode1276

 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型汉堡的数量。

猜你喜欢

转载自www.cnblogs.com/asenyang/p/11965571.html
今日推荐