zl程序教程

您现在的位置是:首页 >  其他

当前栏目

​LeetCode刷题实战458:可怜的小猪

2023-04-18 12:34:58 时间

算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试。所以,为了提高大家的算法能力,后续每天带大家做一道算法题,题目就从LeetCode上面选 !

今天和大家聊的问题叫做 可怜的小猪,我们先来看题面:

https://leetcode-cn.com/problems/poor-pigs/

示例

示例 1:
输入:buckets = 1000, minutesToDie = 15, minutesToTest = 60
输出:5

示例 2:
输入:buckets = 4, minutesToDie = 15, minutesToTest = 15
输出:2

示例 3:
输入:buckets = 4, minutesToDie = 15, minutesToTest = 30
输出:2

解题

class Solution {
    public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
        
        if(buckets == 1) return 0;
        
        int w = minutesToTest / minutesToDie + 1;
        int re = 1;
        while(Math.pow(w,re) < buckets)
            re ++;
        
        return re;
    }
}

上期推文:

LeetCode1-440题汇总,希望对你有点帮助!

LeetCode刷题实战441:排列硬币

LeetCode刷题实战442:数组中重复的数据

LeetCode刷题实战443:压缩字符串

LeetCode刷题实战444:序列重建

LeetCode刷题实战445:两数相加 II

LeetCode刷题实战446:等差数列划分 II - 子序列

LeetCode刷题实战447:回旋镖的数量

LeetCode刷题实战448:找到所有数组中消失的数字

LeetCode刷题实战449:序列化和反序列化二叉搜索树

LeetCode刷题实战450:删除二叉搜索树中的节点

LeetCode刷题实战451:根据字符出现频率排序

LeetCode刷题实战452:用最少数量的箭引爆气球

LeetCode刷题实战453:最小操作次数使数组元素相等

LeetCode刷题实战454:四数相加 II

LeetCode刷题实战455:分发饼干

LeetCode刷题实战456:132 模式