Gas Station

There are n gas stations along a circular route with specified gas amounts at each station. You have a car with an unlimited gas tank, and the cost to travel between stations is provided. You start with an empty tank at one of the stations. Determine the starting station's index to complete a full cycle, or return -1 if it's not possible. A unique solution is guaranteed.

Constraints

  • n == gas.length == cost.length
  • 1 <= n <= 10^5
  • 0 <= gas[i], cost[i] <= 10^4
Saving… · 2 lines
class Solution:
def gasStation(self, gas: List[int], cost: List[int]) -> int:
Console

Click Run to execute sample tests.