class Solution {
public:
int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
int total = 0, sum = 0, start = 0;
for (int i = 0; i < gas.size(); ++i) {
total += gas[i] - cost[i];
sum += gas[i] - cost[i];
if (sum < 0) {
start = i + 1;
sum = 0;
}
}
return (total < 0) ? -1 : start;
}
};
相关文章
- 04-09[Leetcode 134]汽车加油站 Gas Station (环形)
- 04-09A1072 Gas Station (30分)
- 04-09134. Gas Station (Medium)
- 04-09LeetCode 134. Gas Station
- 04-09制作Station主机的KylinOS启动卡
- 04-09Gas Station|leetcode 贪心
- 04-09Station P1-AndroidTV 10固件
- 04-09Building a Space Station POJ 2031 【最小生成树 prim】
- 04-09poj 2031 Building a Space Station【最小生成树prime】【模板题】
- 04-09Gas Station [LeetCode]