gas station leetcode
来源:互联网 发布:ps4网络nat3转nat2 编辑:程序博客网 时间:2024/05/16 09:41
class Solution {public: int canCompleteCircuit(vector<int> &gas, vector<int> &cost) { int sum=0,total=0,i,start=0; for(i=0;i<gas.size();i++) { sum=sum+gas[i]-cost[i]; total=total+gas[i]-cost[i]; if(sum<0) { sum=0; start=(i+1)%gas.size(); } } if(total<0) return -1; else return start; }};
这题用笨办法会超时,看了http://blog.csdn.net/jellyyin/article/details/12245429,才知道好办法
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
- codeforces 400C - Inna and Huge Candy Matrix
- mpg123源码详解
- Eclipse git插件提交自动填充
- 图的拓扑排序
- Xamarin.iOS Notes
- gas station leetcode
- CF 389B:Fox and Cross
- 1.求两个数的最大公约数
- TreeView绑定数据库
- Git学习系列(三)版本回退和管理文件的修改及删除操作
- 打开(激活)Ubuntu的root帐号
- CDN
- madplay源代码导读
- 【python2.7】raw_input()和input()区别及用法