zoukankan      html  css  js  c++  java
  • 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型汉堡的数量。

  • 相关阅读:
    Java集合类
    打开Eclipse报错
    FusionWidgets之AngularGauge图
    OLAP 大表和小表并行hash join
    分页SQL模板
    全表扫描分页
    Java中的a++和++a的区别
    JAVA中线程同步方法
    final、finally和finalize的区别
    HashMap和Hashtable的异同点
  • 原文地址:https://www.cnblogs.com/asenyang/p/11965571.html
Copyright © 2011-2022 走看看