https://leetcode.com/problems/gas-station/


class Solution:

def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
go = [g-c for g,c in zip(gas, cost)] * 2
start, num, fuel, lim = 0, 0, 0, len(go)//2
while start < lim:
if fuel + go[start + num] < 0:
fuel -= go[start]
start += 1
num -= 1
else :
fuel += go[start + num]
num += 1
if num == lim :
return start
return -1



시작 station부터 n개의 누적합이 전부 양수인 점을 찾는데

O(N^2)을 돌리기 싫으니 슬라이딩 윈도우로 앞에서 구했던 값들을 사용