Fork自 inscode / Python
class Solution(object): def canCompleteCircuit(self, gas, cost): """ :type gas: List[int] :type cost: List[int] :rtype: int """ n = len(gas) if sum(gas) < sum(cost): return -1 else: start = 0 path = 0 for i in range(n): path = path + (gas[i] - cost[i]) if path < 0: start = i + 1 path = 0 return start