当前位置:网站首页>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]);
}
边栏推荐
- swift笔记
- [QNX Hypervisor 2.2用户手册]6.2.2 Guest与Host之间通信
- Solr基础操作9
- How to write controller layer code gracefully?
- Some specifications based on zfoo development project
- 剑指 Offer II 035. 最小时间差
- [advanced C language] address book implementation
- vim插件管理器vim-plug安装方法
- There is no web-based development for the reward platform. Which is suitable for native development or mixed development?
- Analysis of define incdir command in TCL script of Modelsim
猜你喜欢

After 8 years of polishing, "dream factory of game design" released an epic update!

云原生爱好者周刊:炫酷的 Grafana 监控面板集合

vsftp 与 TFTP 与 samba 与 nfs 复习

Root cause of glideexception: failed decodepath{directbytebuffer- > gifdrawable- > drawable}

GET 和 POST请求的本质区别是什么?

Digital collection of cultural relics, opening a new way of cultural inheritance

Inspiration collection · evaluation of creative writing software: flomo, obsidian memo, napkin, flowus

Basic operations such as MySQL startup under Windows platform
![Clone undirected graph [bfs accesses each edge but not only nodes]](/img/34/2a1b737b6095293f868ec6aec0ceeb.png)
Clone undirected graph [bfs accesses each edge but not only nodes]

剑指 Offer II 037. 小行星碰撞
随机推荐
俞敏洪:我的退与进;架构师必须了解的5种最佳软件架构模式;Redis夺命52连问|码农周刊VIP会员专属邮件周报 Vol.096
What is IGMP? What is the difference between IGMP and ICMP?
Basic tutorial for installing monggodb in win10
有流量,但没有销售?增加网站销量的 6 个步骤
Andorid source build/envsetup.sh 该知道的细节
Color space conversion in video tonemapping (HDR to SDR) (bt2020 to bt709, YCbCr, YUV and RGB)
MySQL multi table query
多数元素II[求众数类之摩尔投票法]
swift笔记
Three postures of anti CSRF blasting
QT learning 01 GUI program principle analysis
Code analysis platform sonarqube actual combat
Do mysqlcdc data not support windowing functions like row_ Number, lead
MySQL:SQL概述及数据库系统介绍 | 黑马程序员
Solr基础操作16
代码分析平台 SonarQube 实战
Activity invitation | the Apache Doris community essay and speech solicitation activity has begun!
Solr basic operation 11
500 error occurred after importing skins folder into solo blog skin
Review of vsftp, TFTP, samba and NFS