#
#
# @param gas int整型一维数组
# @param cost int整型一维数组
# @return int整型
#
class Solution:
def canCompleteCircuit(self , gas , cost ):
# write code here
b=[]
for i in range(len(gas)):
b.append(gas[i]-cost[i])
if max(b)<0:
return -1
i=b.index(max(b))
while(i<len(gas)):
next=(i+1)%len(gas)
curOil=b[i]
while(next!=i and next<len(gas)):
curOil +=b[next]
if curOil<0:
break
next=(next+1)%len(gas)
if curOil>=0:
return i
i += 1
return -1

京公网安备 11010502036488号