加油站

加油站

 

 

class Solution {
public:
    int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
        int sum=0;
        int start=0;
        int minsum=INT_MAX;
    //从0开始求sum,最低点小于0是不行的,所以我们直接找最低点处开始
        for(int i=0;i<gas.size();i++)
        {
            sum+=gas[i]-cost[i];
            if(sum<minsum)
            {
                start=i+1;
                minsum=sum;
            }
        }
        if(sum<0)
        {
            return -1;
        }
        return start==gas.size()?0:start;
    }
};   

 

TRANSLATE with x English
Arabic Hebrew Polish
Bulgarian Hindi Portuguese
Catalan Hmong Daw Romanian
Chinese Simplified Hungarian Russian
Chinese Traditional Indonesian Slovak
Czech Italian Slovenian
Danish Japanese Spanish
Dutch Klingon Swedish
English Korean Thai
Estonian Latvian Turkish
Finnish Lithuanian Ukrainian
French Malay Urdu
German Maltese Vietnamese
Greek Norwegian Welsh
Haitian Creole Persian  
加油站 加油站 加油站 加油站   TRANSLATE with 加油站 COPY THE URL BELOW 加油站 加油站 Back EMBED THE SNIPPET BELOW IN YOUR SITE 加油站 Enable collaborative features and customize widget: Bing Webmaster Portal Back
上一篇:做一个英译中的命令行工具


下一篇:Markdown编辑规则学习