[LeetCode]Gas Station
来源:互联网 发布:免费查海关数据的网站 编辑:程序博客网 时间:2024/05/16 06:11
class Solution {public: int canCompleteCircuit(vector<int> &gas, vector<int> &cost) { // Note: The Solution object is instantiated only once and is reused by each test case. int n = gas.size(); int curSum = 0; int total = 0; int pos = 0; for(int i = 0; i < n; ++i) { int curRemain = gas[i]-cost[i]; if(curSum >= 0) curSum += curRemain; else curSum = curRemain, pos = i; total += curRemain; } return total >= 0 ? pos: -1; }};
- 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
- iOS7适配——导航栏问题
- java内存泄露和内存溢出
- 语法改进,实用!new in xcode4.5
- sdf
- eclipse的操作
- [LeetCode]Gas Station
- 闪回删除和管理回收站
- Android 滑动效果进阶篇(六)—— 倒影效果
- Restlet 输出日志说明
- 升级CentOS遇到Unable to find the ncurses libraries or the required header files错误
- jquery选择器之层次选择器
- [LeetCode]Clone Graph
- perl 中的散列作为多维数组、结构体使用
- linux 管道(linux Pipe与named Pipe)