Solved LeetCode program · 642 of 1,000
#0871 · Minimum Number of Refueling Stops
Original English source
Keep a shared places holding 10, 20, 30, and 60. Keep a shared fuels holding 60, 30, 30, and 40. Keep a shared reach holding 0, 0, 0, 0, and 0.
To expand from spot (a whole number).
If spot is less than 0, return. The position is item spot of places. The raised is item spot of reach plus item spot of fuels.
If item spot of reach is at least position and raised is more than item (spot plus 1) of reach, set item (spot plus 1) of reach to raised. Expand from spot minus 1.
Set item 0 of reach to 10.
For every station from 0 to 3.
Expand from station.
The answer is -1.
For every stops from 0 to 4.
If item stops of reach is at least 100 and answer is -1, set answer to stops.
Show answer.
Expected stdout
2