当前位置:网站首页>Sword finger offer II 035 Minimum time difference - quick sort plus data conversion
Sword finger offer II 035 Minimum time difference - quick sort plus data conversion
2022-07-07 01:20:00 【Mr Gao】
The finger of the sword Offer II 035. Minimum time difference - Quick sort plus data conversion
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 .
Example 1:
Input :timePoints = [“23:59”,“00:00”]
Output :1
Example 2:
Input :timePoints = [“00:00”,“23:59”,“00:00”]
Output :0
The solution code is as follows :
void quick(int *a,int low,int high){
if(low<high){
// printf("**%d ",a[low]);
int l=low,h=high,p=a[low];
while(low<high){
while(low<high&&a[high]>=p){
high--;
}
a[low]=a[high];
while(low<high&&a[low]<=p){
low++;
}
a[high]=a[low];
}
a[low]=p;
quick(a,l,low-1);
quick(a,low+1,h);
}
}
int findMinDifference(char ** timePoints, int timePointsSize){
int *a=(int *)malloc(sizeof(int )*timePointsSize);
int i;
for(i=0;i<timePointsSize;i++){
char *s=timePoints[i];
// printf("%s ",s);
int z=0;
int j=0;
while(s[j]!=':'){
z=z*10+s[j]-'0';
j++;
}
int b=0;
j++;
while(s[j]!='\0'){
b=b*10+s[j]-'0';
j++;
}
a[i]=z*60+b;
// printf("%d %d %d ",a[i],z,b);
}
quick(a,0,timePointsSize-1);
int min=10000;
int t=fmin(a[timePointsSize-1]-a[0],1440-a[timePointsSize-1]+a[0]);
if(t<min){
min=t;
}
for(i=1;i<timePointsSize;i++){
// printf("-%d ",a[i]);
int t=fmin(a[i]-a[i-1],1440-a[i]+a[i-1]);
if(t<min){
min=t;
}
}
return min;
}
边栏推荐
- Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
- Case development of landlord fighting game
- 力扣1037. 有效的回旋镖
- Eventbus source code analysis
- 安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
- Oracle:CDB限制PDB资源实战
- Tensorflow GPU installation
- [Niuke] b-complete square
- How to evaluate load balancing performance parameters?
- ARM裸板调试之JTAG原理
猜你喜欢
405 method not allowed appears when the third party jumps to the website
Force buckle 1037 Effective boomerang
Wood extraction in Halcon
资产安全问题或制约加密行业发展 风控+合规成为平台破局关键
界面控件DevExpress WinForms皮肤编辑器的这个补丁,你了解了吗?
"Exquisite store manager" youth entrepreneurship incubation camp - the first phase of Shunde market has been successfully completed!
Dynamic planning idea "from getting started to giving up"
Windows installation mysql8 (5 minutes)
Analysis of mutex principle in golang
【JVM调优实战100例】05——方法区调优实战(下)
随机推荐
Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
Transformation transformation operator
Neon Optimization: summary of performance optimization experience
pytorch之数据类型tensor
MySQL script batch queries all tables containing specified field types in the database
[100 cases of JVM tuning practice] 04 - Method area tuning practice (Part 1)
7.6模拟赛总结
树莓派/arm设备上安装火狐Firefox浏览器
Can the system hibernation file be deleted? How to delete the system hibernation file
gnet: 一个轻量级且高性能的 Go 网络框架 使用笔记
Windows installation mysql8 (5 minutes)
2022 Google CTF segfault Labyrinth WP
go-zero微服务实战系列(九、极致优化秒杀性能)
Fastdfs data migration operation record
Make a simple graphical interface with Tkinter
字节P7专业级讲解:接口测试常用工具及测试方法,福利文
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
pyflink的安装和测试
[batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
【js】获取当前时间的前后n天或前后n个月(时分秒年月日都可)