class Solution(object):
def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
n = len(gas)
remain = 0 #计算全程剩余
run = 0 #计算当前消耗
start = 0 #记录起点
for i in range(n):
remain += gas[i] - cost[i]
run += gas[i] - cost[i]
#若当前消耗<0,起点后移
if run < 0:
start = i + 1
run = 0
return start if remain >= 0 else -1