当前位置:网站首页>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;
}
};
边栏推荐
- Meta,元宇宙和广告双败的一季
- TiCDC synchronization delay problem
- [Numpy] np.select
- snap软件中哨兵2A数据预处理及六种常用植被指数的计算
- 【kaggle】Spaceship Titanic - 预测哪些乘客被运送到另一个维度【CatBoost - 10%】
- Hash table implementation code
- 传奇服务端GOM引擎和GEE引擎区别在哪里?
- Gee engine modification UI interface graphic tutorial
- npm出现报错 npm WARN config global `--global`, `--local` are deprecated. Use `--location=global
- npm install 报错问题解决合集
猜你喜欢

Leetcode65. 有效数字

MIT指出公开预训练模型不能乱用

MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)

mysql5.7.35安装配置教程【超级详细安装教程】

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

"Industrial flaw detection depth study method" the latest 2022 research were reviewed

Chapter 6 c + + primer notes 】 【 function
![[网鼎杯 2020 半决赛]AliceWebsite](/img/59/5b87c1ce83adc4027efe8fff5d39ef.png)
[网鼎杯 2020 半决赛]AliceWebsite

38.【string下章】

IO flow: node flow and process flow summarized in detail.
随机推荐
Create and copy conda environment
SIP system composition format
如何监控海外服务器性能
MySQL基础(DDL、DML、DQL)
Interceptors and filters (3) @interface custom annotation interception
Windows系统Mysql8版本的安装教程
C语言小游戏------贪吃蛇----小白专用
开关电源-LLC基本原理
2022年年中总结:行而不辍,未来可期
万字长文,揭秘华为数据治理体系!
Go-Excelize API源码阅读(七)—— CopySheet(from, to int)
JS_ deleting the invalid data in the array undefined '0' null false NaN
线程池拒绝策略详解
mysql5.7.35安装配置教程【超级详细安装教程】
asyncawait和promise的区别
25年来最经典的电影特效名场面
Scala 简介一
How to set the explosion rate of legendary humanoid?Humanoid increase tutorial
The IDEA of Database plug-in Database Navigator plug-in
Gee engine modification UI interface graphic tutorial