← 返回数学题库
5727脑筋急转弯中等brainteasermedium

The Circular Gas Station Tour

题目

Five gas stations are arranged in a circle, numbered 1 through 5 in clockwise order. Driving clockwise from station i to the next station costs a fixed amount of fuel. At station i you may pick up gas[i] units, and the drive from station i to the next one consumes cost[i] units. The amounts are gas = [1, 2, 3, 4, 5] and cost = [3, 4, 5, 1, 2]. Your tank starts empty and has unlimited capacity. From which single station can you start, pick up its gas, and drive all the way around the circle returning to the start without the tank ever going negative?

解题计时

0:00

提交作答时记录,用于后续平均用时统计。

你的答案