leetcode加油站问题 def f(gas, cost): length = len(gas) for i in range(length): temp = i if gas[i] >= cost[i]: x = gas[i] - cost[i] for _ in range(length-1): if x < 0: break if temp >= length-1: temp = -1 x += gas[temp+1] - cost[temp+1] temp += 1 if x >= 0: return i return -1