/*遍历一边找出累加最小值, val是否小于0判断是否有存在的路线*/ int canCompleteCircuit(int* gas, int gasSize, int* cost, int costSize){ int i, j, val=0, minVal=2147483647; for (i=0; i<gasSize; i++){ val+=gas[i]-cost[i]; if(val<minVal){ minVal=val; j=i; } } return (val<0)?-1 :(j+1)%gasSize; }