134. Gas Station
Difficulty: Medium
There are _N_ gas stations along a circular route, where the amount of gas at station _i_ is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station _i_ to its next station (_i_+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station’s index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
Note:
- If there exists a solution, it is guaranteed to be unique.
- Both input arrays are non-empty and have the same length.
- Each element in the input arrays is a non-negative integer.
Example 1:
1 | **Input:** |
Example 2:
1 | **Input:** |
Solution
Language: Java
1 | class Solution { |