프로그래밍/LeetCode

[LeetCode][Python3] 134. Gas Station

snoopybox 2019. 4. 8. 02:16

Problem :

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


My Solution :

class Solution:
def canCompleteCircuit(self, gas, cost):
before = tank = start = 0
for i in range(len(gas)):
tank += (gas[i] - cost[i])
if tank < 0:
before += tank
tank = 0
start = i+1
return start if 0 <= before + tank else -1
저작자표시 (새창열림)