博客
关于我
Leetcode 134. 加油站 java版 如何解决环路加油站算法
阅读量:832 次
发布时间:2023-01-30

本文共 258 字,大约阅读时间需要 1 分钟。

问题描述:在一条环路上有n个加油站,第i个加油站有汽油gas[i]升。有一辆油箱容量无限的车,需要从第i个加油站开往i+1个加油站,消耗汽油cost[i]升。车子的油箱一开始是空的。你需要从这些加油站中的一个出发,判断是否可以绕整个环路行驶一圈。如果能够做到,返回你选择的起始加油站编号;否则返回-1。题目保证,如果存在解的话,解是唯一的。

示例:输入:gas = [1,2,3,4,5], cost = [3,4,5,1,2],输出:3。原因是从第三个加油站开始,汽油足够满足整个路线的消耗,实现绕环路一圈的目标。

转载地址:http://gxgyk.baihongyu.com/

你可能感兴趣的文章
python | alabaster,一个强大的 关于alabaster 主题 Python 库!
查看>>
python | algorithms,一个超赞的 集合常用算法的Python 库!
查看>>
python调用jpype 报错:OSError JVM is already started和JVM cannot be restarted
查看>>
python | authlib,一个强大的 Python 库!
查看>>
python | awswrangler,一个高效的 Python 库!
查看>>
python | bashplotlib,一个有趣的Python库!
查看>>
python | bentoml,一个超级厉害的 模型部署 Python 库!
查看>>
python调用jar包的模块_python调用jar包
查看>>
python | black,一个神奇的 代码格式化工具 Python 库!
查看>>
python | bleach,一个超强的 Python 库!
查看>>
python | cartopy,一个有趣的 Python 库!
查看>>
python | cloud-init,一个实用的 云计算 Python 库!
查看>>
python | code2flow,一个神奇的 Python 库!
查看>>
python | cudf,一个超实用的 Python 库!
查看>>
python | daphne,一个非常nice的 Python 库!
查看>>
python调用halcon
查看>>
python | doit,一个非常实用的 Python 库!
查看>>
python | easyocr,一个超厉害的 关于OCR的 Python 库!
查看>>
python | fastFM,一个高级的 Python 库!
查看>>
python | feature_engine,一个实用的 Python 库!
查看>>