https://leetcode-cn.com/problems/gas-station/
class Solution(object):
def canCompleteCircuit(self, gas, cost):
"""
:type gas: List[int]
:type cost: List[int]
:rtype: int
"""
n=len(gas)
start=0
is_skip=False
while start<n:
#print("start=",start)
sumgas=0
flag=True
for i in range(start,start+n):
i=i%n
#print(i)
sumgas+=gas[i]
if sumgas-cost[i]<0:
flag=False
is_skip=True
break
else:
sumgas=sumgas-cost[i]
if flag:
return start
if is_skip:
if start<=i:
start=i
else:
return -1
start+=1
return -1