123.py 501 字节
Newer Older
6
UPDATE  
622b169008dbb7338e377ec6 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
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