UPDATE

上级 df352508
class Solution(object):
def canCompleteCircuit(self, gas, cost):
"""
:type gas: List[int]
:type cost: List[int]
:rtype: int
"""
n = len(gas)
if sum(gas) < sum(cost):
return -1
else:
start = 0
path = 0
for i in range(n):
path = path + (gas[i] - cost[i])
if path < 0:
start = i + 1
path = 0
return start
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册