标签:
我觉得这道题是dp比较有趣的应用吧,但是老用不熟
sigh一下
public class Solution { public int canCompleteCircuit(int[] gas, int[] cost) { int total=0, curRem=0, curSum=0,start=0; for(int i=0;i<gas.length;i++){ curRem = gas[i]-cost[i]; if(curSum>=0){ curSum += curRem; }else{ curSum = curRem; start = i; } total += curRem; } return total<0? -1: start; } }
标签:
原文地址:http://www.cnblogs.com/jiajiaxingxing/p/4570728.html