题目:
题解:
class Solution:
def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
start, cur_res, total_res = 0, 0, 0
for i in range(len(gas)):
cur_res += gas[i] - cost[i]
total_res += gas[i] - cost[i]
if cur_res < 0:
cur_res = 0
start = i + 1
if total_res < 0:
return -1
else:
return start