当前位置:网站首页>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;
}
边栏推荐
- [HFCTF2020]BabyUpload session解析引擎
- SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
- tensorflow 1.14指定gpu运行设置
- boot - prometheus-push gateway 使用
- NEON优化:关于交叉存取与反向交叉存取
- Install Firefox browser on raspberry pie /arm device
- from . cv2 import * ImportError: libGL. so. 1: cannot open shared object file: No such file or direc
- The MySQL database in Alibaba cloud was attacked, and finally the data was found
- Supersocket 1.6 creates a simple socket server with message length in the header
- mysql: error while loading shared libraries: libtinfo. so. 5: cannot open shared object file: No such
猜你喜欢
boot - prometheus-push gateway 使用
ClickHouse字段分组聚合、按照任意时间段粒度查询SQL
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
JTAG principle of arm bare board debugging
Lldp compatible CDP function configuration
子网划分、构造超网 典型题
Make Jar, Not War
AI 从代码中自动生成注释文档
Windows installation mysql8 (5 minutes)
随机推荐
Failed to successfully launch or connect to a child MSBuild. exe process. Verify that the MSBuild. exe
405 method not allowed appears when the third party jumps to the website
斗地主游戏的案例开发
Body mass index program, entry to write dead applet project
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
【案例分享】网络环路检测基本功能配置
There is an error in the paddehub application
golang中的atomic,以及CAS操作
NEON优化:性能优化经验总结
Js逆向——捅了【马蜂窝】的ob混淆与加速乐
Grc: personal information protection law, personal privacy, corporate risk compliance governance
[batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
Rainstorm effect in levels - ue5
界面控件DevExpress WinForms皮肤编辑器的这个补丁,你了解了吗?
系统休眠文件可以删除吗 系统休眠文件怎么删除
THREE.AxesHelper is not a constructor
第三方跳转网站 出现 405 Method Not Allowed
接收用户输入,身高BMI体重指数检测小业务入门案例
Oracle:CDB限制PDB资源实战