LeetCode 458. Poor Pigs

题目描述

458. 可怜的小猪

AC代码

class Solution {
    public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
        //一头猪在测试时间内最多可以喝几次水
        int base=minutesToTest/minutesToDie+1;
        int pignum=0,n=1;
        while(n<buckets){
            pignum++;
            n*=base;
        }
        return pignum;
    }
}

你可能感兴趣的:(leetcode)