微智科技网
您的当前位置:首页134. Gas Station

134. Gas Station

来源:微智科技网
class Solution {
    public int canCompleteCircuit(int[] gas, int[] cost) {
        int total=0,cur=0,start=0;
        for(int i=0;i<gas.length;i++)
        {
            cur+=gas[i]-cost[i];
            total+=gas[i]-cost[i];
            if(cur<0)
            {
                cur=0;
                start=i+1;
            }
        }
        return total>=0?start:-1;
    }
}

  

转载于:https://www.cnblogs.com/asuran/p/7634045.html

因篇幅问题不能全部显示,请点此查看更多更全内容