Leetcode 902 Solution
This article provides solution to leetcode question 902 (minimum-number-of-refueling-stops)
Access this page by simply typing in "lcs 902" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/minimum-number-of-refueling-stops
Solution
class Solution:
def minRefuelStops(self, target: int, startFuel: int, stations: List[List[int]]) -> int:
currentFuel = startFuel
ans = 0
i = 0
q = []
while currentFuel < target:
while i < len(stations) and currentFuel >= stations[i][0]:
heapq.heappush(q, -stations[i][1])
i += 1
if not q:
return -1
currentFuel -= heapq.heappop(q)
ans += 1
return ans