码迷,mamicode.com
首页 > 其他好文 > 详细

Gas Station

时间:2014-10-22 12:16:44      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   sp   div   

 

class Solution:
    # @param gas, a list of integers
    # @param cost, a list of integers
    # @return an integer
    def canCompleteCircuit(self, gas, cost):
        additional_gas=[]
        for i in range(len(gas)):
            additional_gas.append(gas[i]-cost[i])
        if sum(additional_gas)<0:
            return -1
        start=0
        for i in range(1,len(gas)):
            if (additional_gas[i]>=0 and additional_gas[i-1]<0):
                start=i
        return start

 

Gas Station

标签:style   blog   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/iois/p/4042484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!