给出每个公交车完成一次trip所需时间time[i],以及所有需要完成的trip数totalTrips,问最少多久能完成所有trips,同一时刻可以派出任意辆车
直接二分结果
1 #2187
2 #Runtime: 2092 ms (Beats 65.38%)
3 #Memory: 24.8 MB (Beats 46.15%)
4
5 class Solution(object):
6 def minimumTime(self, time, totalTrips):
7 """
8 :type time: List[int]
9 :type totalTrips: int
10 :rtype: int
11 """
12 l = 0
13 r = totalTrips * time[0]
14 while l < r:
15 mid = (l + r) // 2
16 tr = 0
17 for i in time:
18 tr += mid // i
19 if tr < totalTrips:
20 l = mid + 1
21 else:
22 r = mid
23 return l