Leetcode 458 Python

解题思路:每只猪负责检查一个维度,假设x只猪共能检查n次,则能检查的数量为(n+1)^x个桶(最后一维不需检查)

class Solution(object):
    def poorPigs(self, buckets, minutesToDie, minutesToTest):
        """
        :type buckets: int
        :type minutesToDie: int
        :type minutesToTest: int
        :rtype: int
        """
        t = minutesToTest/minutesToDie
        if minutesToTest%minutesToDie > 0:
            t += 1
        t+=1
        pig = 0
        while pow(t,pig) < buckets:
            pig += 1
        return pig

你可能感兴趣的:(Leetcode)