加油站
作者:互联网
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 TRANSLATE with COPY THE URL BELOW Back EMBED THE SNIPPET BELOW IN YOUR SITE Enable collaborative features and customize widget: Bing Webmaster Portal Back
标签:TRANSLATE,int,sum,加油站,vector,location,document 来源: https://www.cnblogs.com/libin123/p/15237714.html