香蕉

Leetcode 875. 爱吃香蕉的珂珂

匿名 (未验证) 提交于 2019-12-02 23:32:01
N i piles[i] H K K K 珂珂喜欢慢慢吃,但仍然想在警卫回来前吃掉所有的香蕉。 H K ( K 示例 1: 输入: piles = [3,6,7,11], H = 8 输出: 4 输入: piles = [30,11,23,4,20], H = 5 输出: 30 输入: piles = [30,11,23,4,20], H = 6 输出: 23 提示: 1 <= piles.length <= 10^4 piles.length <= H <= 10^9 1 <= piles[i] <= 10^9 这是一个经典的二分搜索问题,使用经典的模板 class Solution { public: int minEatingSpeed(vector<int>& piles, int H) { int left = 1, right = 100000010; while(left<=right){ int mid = left + (right-left)/2; if(check(piles, H, mid)) right = mid-1; else left = mid + 1; } return left; } bool check(vector<int> piles, int H, int K){ int h = 0; for(int i=0;i<piles.size(

pythonday10

匿名 (未验证) 提交于 2019-12-02 22:56:40
一. 函数参数--动态传参 def chi(quality_food, junk_food): print("我要吃", quality_food, junk_food) chi("大米饭", "小米饭") # "大米饭"传递给quality_food "小米饭"传递给junk_food 按照位置传 def chi(*food): print("我要吃", food) chi("大米饭", "小米饭") 结果: 我要吃 ('大米饭', '小米饭') # 多个参数传递进去. 收到的内容是元组tuple     注意:动态接收实参的时候, 动态形参必须在位置形参后面!     否则传递进去的所有位置实参都被动态形参接收,后面的位置形参则就收不到参数.      def chi(a, b, c='馒头', *food): print(a, b, c, food) chi("香蕉", "菠萝") # 香蕉 菠萝 馒头 (). 默认值生效 chi("香蕉", "菠萝", "葫芦娃") # 香蕉 菠萝 葫芦娃 () 默认值不生效 chi("香蕉", "菠萝", "葫芦娃", "口罩") # 香蕉 菠萝 葫芦娃 ('口罩',) 默认值不生效 def chi(a, b, *food, c="娃哈哈"): print(a, b, food, c) chi("香蕉", "菠萝") # 香蕉 菠萝 ()