![图片标题 图片说明](https://img-blog.csdnimg.cn/img_convert/2d461992350c40991ac27a29b4af93f9.png)
/**
*
* @param gas int整型一维数组
* @param cost int整型一维数组
* @return int整型
*/
function canCompleteCircuit( gas , cost ) {
// write code here
var start = gas.length - 1;
var end = 0;
var sum = gas[start] - cost[start]
while(start>end){
if(sum>=0){
sum += gas[end] - cost[end];
++end;
}else{
--start;
sum += gas[start] - cost[start];
}
}
return sum>=0 ? start : -1;
}
module.exports = {
canCompleteCircuit : canCompleteCircuit
};