当前位置:网站首页>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;
}
边栏推荐
- px em rem的区别
- C语言中的函数(详解)
- AWT common components, FileDialog file selection box
- Arc135 C (the proof is not very clear)
- 509. 斐波那契数、爬楼梯所有路径、爬楼梯最小花费
- Weekly summary (*63): about positive energy
- Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
- Webrtc quickly set up video call and video conference
- C # character similarity comparison general class
- ES6 模块化
猜你喜欢
一键过滤选择百度网盘文件
冲击继电器JC-7/11/DC110V
buuctf-pwn write-ups (8)
谷歌 Chrome 浏览器将支持选取文字翻译功能
Penetration tool - sqlmap
C语言练习题(递归)
transformer坑了多少算力
Yiwen unlocks Huawei's new cloud skills - the whole process of aiot development [device access - ESP end-to-side data collection [mqtt]- real time data analysis] (step-by-step screenshot is more detai
gslb(global server load balance)技术的一点理解
BUU-Crypto-Cipher
随机推荐
冲击继电器JC-7/11/DC110V
High performance parallel programming and optimization | lesson 02 homework at home
LayoutManager布局管理器:FlowLayout、BorderLayout、GridLayout、GridBagLayout、CardLayout、BoxLayout
ES6 模块化
AWT介绍
Overview of relevant subclasses of beanfactorypostprocessor and beanpostprocessor
19. Framebuffer application programming
云原生架构实战案例及优化解决方案
"In simple language programming competition (basic)" part 1 Introduction to language Chapter 3 branch structure programming
Weekly summary (*63): about positive energy
1480. 一维数组的动态和
JS扁平化数形结构的数组
Introduction to AMBA
[Excel] 数据透视图
FRP intranet penetration, reverse proxy
Layoutmanager layout manager: flowlayout, borderlayout, GridLayout, gridbaglayout, CardLayout, BoxLayout
谷歌 Chrome 浏览器将支持选取文字翻译功能
Halcon image calibration enables subsequent image processing to become the same as the template image
Online shrimp music will be closed in January next year. Netizens call No
Take you to quickly learn how to use qsort and simulate qsort