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