首页 > 代码库 > Gas Station

Gas Station

 

class Solution:    # @param gas, a list of integers    # @param cost, a list of integers    # @return an integer    def canCompleteCircuit(self, gas, cost):        additional_gas=[]        for i in range(len(gas)):            additional_gas.append(gas[i]-cost[i])        if sum(additional_gas)<0:            return -1        start=0        for i in range(1,len(gas)):            if (additional_gas[i]>=0 and additional_gas[i-1]<0):                start=i        return start

 

Gas Station