当前位置:网站首页>2022.7.2-----leetcode. eight hundred and seventy-one
2022.7.2-----leetcode. eight hundred and seventy-one
2022-07-04 05:55:00 【Lu 727】
public int minRefuelStops(int target, int startFuel, int[][] stations) {
// The amount of fuel you can choose for a journey
PriorityQueue<Integer> pq = new PriorityQueue<Integer>((a, b) -> b - a);
int ans = 0,end = startFuel;// The maximum distance of a journey
int n = stations.length;
for (int i = 0; i < n; i++) {
if(end>=target) return ans;// If you can reach the end of a journey, you will return
// After reaching the maximum distance , Select the maximum fuel volume , Until it's enough to reach the next station , Start the next journey
if(stations[i][0]>end){
while(!pq.isEmpty()) {
end+=pq.poll();
ans++;
if(end>=stations[i][0]) break;
}
if(end<stations[i][0]) return -1;// Unable to reach the next site
}
pq.add(stations[i][1]);// Add the amount of fuel that can reach the station
}
// After passing all sites , Judge whether you can reach the end
if(end<target){
while(!pq.isEmpty()) {
end+=pq.poll();
ans++;
if(end>=target) return ans;
}
return -1;
}
return ans;
}边栏推荐
- Input displays the currently selected picture
- Experience weekly report no. 102 (July 4, 2022)
- Arc135 C (the proof is not very clear)
- BUU-Reverse-easyre
- left_and_right_net正常版本
- 报错cvc-complex-type.2.4.a: 发现了以元素 ‘base-extension‘ 开头的无效内容。应以 ‘{layoutlib}‘ 之一开头。
- Design and implementation of redis 7.0 multi part AOF
- Kubernets first meeting
- Invalid revision: 3.18.1-g262b901-dirty
- Programmers don't talk about morality, and use multithreading for Heisi's girlfriend
猜你喜欢

Online shrimp music will be closed in January next year. Netizens call No

一键过滤选择百度网盘文件

测试岗的中年危机该如何选择?是坚守还是另寻出路?且看下文

配置交叉编译工具链和环境变量

webrtc 快速搭建 视频通话 视频会议

(4) Canal multi instance use

ANSYS command

Input displays the currently selected picture

Win10 clear quick access - leave no trace

Sword finger offer II 038 Daily temperature
随机推荐
724. Find the central subscript of the array
509. 斐波那契数、爬楼梯所有路径、爬楼梯最小花费
MySQL的information_schema数据库
One click filtering to select Baidu online disk files
Detectron:训练自己的数据集——将自己的数据格式转换成COCO格式
Nexus 6p从8.0降级6.0+root
Take you to quickly learn how to use qsort and simulate qsort
体验碎周报第 102 期(2022.7.4)
el-select如何实现懒加载(带搜索功能)
How much computing power does transformer have
Compound nonlinear feedback control (2)
【微服务】Nacos集群搭建以及加载文件配置
APScheduler如何设置任务不并发(即第一个任务执行完再执行下一个)?
Component、Container容器常用API详解:Frame、Panel、ScrollPane
[excel] PivotChart
724. 寻找数组的中心下标
The end of the Internet is rural revitalization
How to configure static IP for Kali virtual machine
Leakage detection relay jy82-2p
Kubernets first meeting