Skip to content

Commit 62613e3

Browse files
authored
Update Solution.py
1 parent dd6291d commit 62613e3

File tree

1 file changed

+7
-4
lines changed
  • solution/1800-1899/1870.Minimum Speed to Arrive on Time

1 file changed

+7
-4
lines changed
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
class Solution:
22
def minSpeedOnTime(self, dist: List[int], hour: float) -> int:
3-
def check(speed):
4-
res = 0
3+
def check(v: int) -> bool:
4+
s = 0
55
for i, d in enumerate(dist):
6-
res += (d / speed) if i == len(dist) - 1 else math.ceil(d / speed)
7-
return res <= hour
6+
t = d / v
7+
s += t if i == len(dist) - 1 else ceil(t)
8+
return s <= hour
89

10+
if len(dist) > ceil(hour):
11+
return -1
912
r = 10**7 + 1
1013
ans = bisect_left(range(1, r), True, key=check) + 1
1114
return -1 if ans == r else ans

0 commit comments

Comments
 (0)