LeetCode之Gas Station
来源:互联网 发布:大数据与人工智能 编辑:程序博客网 时间:2024/06/05 09:32
/*设置两个两个变量,用sum变量表示当前出发的点是否可行,total变量表示整个方法是否可行。方法参考自:https://github.com/soulmachine/leetcode*/ class Solution {public: int canCompleteCircuit(vector<int> &gas, vector<int> &cost) { int sum(0), total(0); int start(-1); for(int i = 0; i < gas.size(); ++i){ sum += gas[i] - cost[i]; total += gas[i] - cost[i]; if(sum < 0){ start = i; sum = 0; } } return total >= 0 ? start + 1 : -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 OJ 之 Gas Station (加油站)
- LeetCode:Gas Station
- [LeetCode] Gas Station
- [leetcode]Gas Station
- Leetcode: Gas Station
- LeetCode:Gas Station
- [LeetCode] Gas Station
- leetcode Gas Station
- getFragmentManager与getChildFragmentManager
- Docker实践8:Compose
- oracle优化15
- 关于IAP的一些事儿
- android http code响应码 状态码
- LeetCode之Gas Station
- Invalid content was found starting with element 'taglib'”
- android反编译工具总结
- Sizeof与Strlen的区别与联系(转)
- 开发日志:js修改iframe内的css样式
- iOS边城之动画编程(Core Animation)
- UILocalizedIndexedCollation ios首字母排列
- Linux那些事儿 之 戏说USB(5)我是谁
- 使用 VIRTUALBOX 虚拟机安装 MAC OS X 10.8 MOUNTAIN LION