Gas Station--LeetCode
来源:互联网 发布:nginx cache 编辑:程序博客网 时间:2024/06/07 20:09
There are N gas stations along a circular route, where the amount of gas at stationi isgas[i]
.
You have a car with an unlimited gas tank and it costs cost[i]
of gas to travel from stationi to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once, otherwise return -1.
#include <iostream>#include <vector>int canCompleteCircuit(vector<int> &gas, vector<int> &cost) { int index,cur; int len = gas.size(); int begin=0,curNum; for(begin =0;begin<gas.size();begin++) { cur =0; curNum=0; index = begin; while(curNum<len) { index = index%len; cur +=cost[index]; if(cur< cost[index]) break; else cur -=cont[index]; curNum++; index++; } if(curNum == len) return begin; } return -1; }
0 0
- LeetCode:Gas Station
- [LeetCode] Gas Station
- [leetcode]Gas Station
- Leetcode: Gas Station
- LeetCode:Gas Station
- [LeetCode] Gas Station
- leetcode Gas Station
- [LeetCode]Gas Station
- LeetCode 之 Gas Station
- leetcode Gas Station
- 【Leetcode】Gas Station
- LeetCode | Gas Station
- LeetCode之Gas Station
- Leetcode: Gas Station
- LeetCode OJ:Gas Station
- [LeetCode]134.Gas Station
- [Leetcode] Gas Station (Java)
- gas station leetcode
- 第三届2015年材料科学与环境国际学术研讨会(AMSEM2015)征稿
- 348084677076233553
- Spring MVC 教程,快速入门,深入分析
- PLSQL DEVELOPER汉化包的安装与卸载方法
- 字符编码
- Gas Station--LeetCode
- flex日期比较
- Android向服务器上传中文乱码解决
- mysql数据库表操作
- 动态计算UITableViewCell高度详解
- cookie.setPath()用法
- C++中继承会破坏封装吗?
- ArrayIndexOutOfBoundsException: 4096 while reading image file
- 输出由*组成高为n的等腰三角形