Gas Station

LeetCode: https://leetcode.com/problems/gas-station/

There are n gas stations. You have two integer arrays gas and cost. Return the starting gas station index if you can travel around the circuit once, otherwise return -1.

1def canCompleteCircuit(gas: List[int], cost: List[int]) -> int:
2 if sum(gas) < sum(cost):
3 return -1
4
5 start = 0
6 tank = 0
7 for i in range(len(gas)):
8 tank += gas[i] - cost[i]
9 if tank < 0:
10 start = i + 1
11 tank = 0
12 return start
1
0
2
1
3
2
4
3
5
4
result=false
Step 1 / 3
Step 1:
If total gas < total cost, impossible.
Focus: default
result=false