MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / canCompleteCircuit

Method canCompleteCircuit

Array/GasStation.py:69–90  ·  view source on GitHub ↗

:type gas: List[int] :type cost: List[int] :rtype: int

(self, gas, cost)

Source from the content-addressed store, hash-verified

67"""
68class Solution(object):
69 def canCompleteCircuit(self, gas, cost):
70 """
71 :type gas: List[int]
72 :type cost: List[int]
73 :rtype: int
74 """
75 if sum(gas) < sum(cost):
76 return -1
77
78 rest = 0
79 station = None
80
81 for i in range(len(gas)):
82 if rest + gas[i] - cost[i] >= 0:
83 rest = rest + gas[i] - cost[i]
84 if station is None:
85 station = i
86 else:
87 rest = 0
88 station = None
89
90 return station
91

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected