当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢

2022 IDEA (学生邮箱认证)安装使用教程以及基础配置教程
![[Mysql] LENGTH函数](/img/a1/112cac6b42f8c7abec7e4a6629dffd.png)
[Mysql] LENGTH函数

Bika LIMS - SENAITE using open source LIMS set (users, roles and departments)

微信小程序的登录

投资127亿!深圳,再添一所985

如何把Netflix数据集转换成Movielens格式?

每日优鲜解散疑云:生鲜电商们苦渡生死劫

为什么用了大牌工具后报表开发依然头痛

The most classic special effects scenes in 25 years

MySql 5.7.38下载安装教程 ,并实现在Navicat操作MySql
随机推荐
【个人收藏】一些比较有用的链接
【微信小程序】一文解决button、input、image组件
ISME | 沈其荣团队韦中组-土壤生物障碍发生的根际微生物组诊断
MySQL八股文背诵版
html+css+php+mysql实现注册+登录+修改密码(附完整代码)
BGP简单实验
传奇服务端GOM引擎和GEE引擎区别在哪里?
开关电源-PWM外设简介及MCC配置
Hash table implementation code
The adb for mysql in what platform for development
Meta,元宇宙和广告双败的一季
kotlin协程与线程池
How Navicat Connects to MySQL
38.【string下章】
MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)
JS_ deleting the invalid data in the array undefined '0' null false NaN
苹果手机用久了卡顿,学会这样清理缓存,清理后和新机一样流畅
[GO语言基础] 一.为什么我要学习Golang以及GO语言入门普及
What is the difference between the legendary server GOM engine and the GEE engine?
[WeChat applet] WXSS and global, page configuration