当前位置:网站首页>Sword finger offer II 035 Minimum time difference
Sword finger offer II 035 Minimum time difference
2022-06-30 00:18:00 【Small white yards fly up】
Summary
Use a length of 60*24=1440 Array of , The point in time when the marker appears . Then calculate the distance between the two .
subject
Given a 24 hourly ( Hours : minute “HH:MM”) Time list for , Find the minimum time difference between any two times in the list and express it in minutes .

link :https://leetcode.cn/problems/569nqc/
Ideas
Time list is 24 hourly , And accurate to points .24 Hours , Yes 1440 minute .
We can use a length of 1440 Array of , As a hash table . Drop every minute into every grid . Then traverse each lattice , Record the shortest distance between grids with values . Of course , Don't forget the difference between the earliest and the latest time of the day , Also participate in the calculation .
solution : length 1440 Array of records time
Code
public int findMinDifference(List<String> timePoints) {
int[] list = new int[1440];
for (String timePoint : timePoints) {
// Have the same time point , Go straight back to 0
int hash = hash(timePoint);
if (list[hash] == 1) {
return 0;
}
list[hash]++;
}
int min = Integer.MAX_VALUE;
int start = 0;
int first = 0;
// Initialize start node
for (int i = 0; i < list.length; i++) {
if (list[i] != 0) {
start = i;
first = i;
break;
}
}
for (int i = start + 1; i < list.length; i++) {
if (list[i] > 0) {
min = Math.min(min, i - start);
start = i;
}
}
return Math.min(min, list.length - start + first);
}
private int hash(String timePoint) {
String[] split = timePoint.split(":");
return Integer.parseInt(split[0]) * 60 + Integer.parseInt(split[1]);
}
边栏推荐
- What is flush software? Is it safe to open an account online?
- Digital collection of cultural relics, opening a new way of cultural inheritance
- 基于zfoo开发项目的一些规范
- MySQL functions and constraints
- Vulnhub target -moriartycorp
- [review and Book delivery] 6 interesting R language projects for beginners
- Introduction to reptiles: data capture of Betta barrage, with 11 introductory notes attached
- Solr basic operation 11
- golang7_ TCP programming
- 视频ToneMapping(HDR转SDR)中的颜色空间转换问题(BT2020转BT709,YCbCr、YUV和RGB)
猜你喜欢
![[QNX Hypervisor 2.2用户手册]6.2.2 Guest与Host之间通信](/img/a4/a84f916d3aa2cc59f5b686cd32797a.png)
[QNX Hypervisor 2.2用户手册]6.2.2 Guest与Host之间通信

How to write controller layer code gracefully?

JS draw polar color gradient

数据中台的五个关键要素

剑指 Offer II 037. 小行星碰撞

Andorid source build/envsetup.sh 该知道的细节

Embedded development: Hardware in the loop testing

简要的说一下:Fragment 间的通信方式?
![克隆無向圖[bfs訪問每條邊而不止節點]](/img/34/2a1b737b6095293f868ec6aec0ceeb.png)
克隆無向圖[bfs訪問每條邊而不止節點]

QPainter的使用入门:绘制象棋界面
随机推荐
克隆無向圖[bfs訪問每條邊而不止節點]
云原生爱好者周刊:炫酷的 Grafana 监控面板集合
Summarize Flink runtime architecture in simple terms
代码分析平台 SonarQube 实战
Basic operations such as MySQL startup under Windows platform
AI chief architect 9- huxiaoguang, propeller model library and industry application
Connection query of SQL Server database
gyctf_ 2020_ document
由GlideException: Failed DecodePath{DirectByteBuffer->GifDrawable->Drawable}引起的刨根问底
有流量,但没有销售?增加网站销量的 6 个步骤
Copy linked list with random pointer [space for time --hash record]
Solr基础操作7
IO stream summary
Embedded development: Hardware in the loop testing
Do mysqlcdc data not support windowing functions like row_ Number, lead
Siemens low code version 9.14: meet different needs
[advanced C language] string and memory function (II)
After 8 years of polishing, "dream factory of game design" released an epic update!
Vulnhub target -moriartycorp
Analysis of define incdir command in TCL script of Modelsim