当前位置:网站首页>leetcode134. 加油站
leetcode134. 加油站
2022-07-29 12:55:00 【henujolly】
class Solution {
public:
int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
int sum=0;
for(int i=0;i<gas.size();i++){
sum+=gas[i]-cost[i];
}
if(sum<0) return -1;
int start=0,cur=0;
for(int i=0;i<gas.size();i++){
cur+=gas[i]-cost[i];
if(cur<0){
cur=0;
start=i+1;
}
}
return start;
}
};
边栏推荐
猜你喜欢
DVWA全级别通关教程
每日优鲜解散疑云:生鲜电商们苦渡生死劫
A recent paper summarizes
2022年编程语言排名,官方数据来了,让人大开眼界
C language game ------ greedy snake ---- for Xiaobai
Mysql进阶优化篇01——四万字详解数据库性能分析工具(深入、全面、详细,收藏备用)
超年轻!34岁教授,任985王牌学院副院长!
The most classic special effects scenes in 25 years
The whole process of installing Oracle database on CentOS7
MySQL基础篇(三)-- 数据类型
随机推荐
Meta,元宇宙和广告双败的一季
The torch using summary
asyncawait和promise的区别
2022年编程语言排名,官方数据来了,让人大开眼界
Hash table implementation code
JUC阻塞队列-ArrayBlockingQueue
[Cloud native] Introduction and use of Feign of microservices
苹果手机用久了卡顿,学会这样清理缓存,清理后和新机一样流畅
torch使用总结
SIP系统组成格式
【个人收藏】一些比较有用的链接
用支持LaTex的Markdown语句编辑一个数学公式
IO flow: node flow and process flow summarized in detail.
Sql文件导入数据库-保姆级教程
The adb for mysql in what platform for development
Chapter 6 c + + primer notes 】 【 function
Leetcode67. 二进制求和
详述 TCP 的 TIME_WAIT 状态要维持 2MSL 的原因
The meaning of "last in first out" in stack and "first in first out" in queue
BGP简单实验