## 暴力算法classSolution:defcanCompleteCircuit(self, gas: List[int], cost: List[int])->int:
start =0for i inrange(len(gas)):
index = i
res =0
llen =0while( res>=0and llen<len(gas)):
res += gas[index]- cost[index]
index =(index+1)%len(gas)
llen +=1if res>=0and llen==len(gas):return i
return-1
## 贪心算法classSolution:defcanCompleteCircuit(self, gas: List[int], cost: List[int])->int:
cur =0
total =0
flag =0for i inrange(len(gas)):
cur += gas[i]-cost[i]
total += gas[i]-cost[i]if cur <0:
flag = i+1
cur =0if total<0:return-1return flag