当前位置:网站首页>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;
}
边栏推荐
- Come on, don't spread it out. Fashion cloud secretly takes you to collect "cloud" wool, and then secretly builds a personal website to be the king of scrolls, hehe
- 「笔记」折半搜索(Meet in the Middle)
- Neon Optimization: performance optimization FAQ QA
- In rails, when the resource creation operation fails and render: new is called, why must the URL be changed to the index URL of the resource?
- golang中的WaitGroup实现原理
- Niuke cold training camp 6B (Freund has no green name level)
- Atomic in golang and CAS operations
- How to manage distributed teams?
- [Niuke] [noip2015] jumping stone
- Taro applet enables wxml code compression
猜你喜欢

Make a simple graphical interface with Tkinter

身体质量指数程序,入门写死的小程序项目

Installation of gazebo & connection with ROS

让我们,从头到尾,通透网络I/O模型

How to manage distributed teams?

Transformation transformation operator
![[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)](/img/40/dc45df3cd3ee7642277eff899bc6aa.png)
[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)

1123. 最深叶节点的最近公共祖先

【JVM调优实战100例】05——方法区调优实战(下)

Maidong Internet won the bid of Beijing life insurance to boost customers' brand value
随机推荐
树莓派/arm设备上安装火狐Firefox浏览器
mysql: error while loading shared libraries: libtinfo. so. 5: cannot open shared object file: No such
JTAG debugging experience of arm bare board debugging
golang中的atomic,以及CAS操作
gnet: 一个轻量级且高性能的 Go 网络框架 使用笔记
[JS] obtain the N days before and after the current time or the n months before and after the current time (hour, minute, second, year, month, day)
Oracle:CDB限制PDB资源实战
[牛客] [NOIP2015]跳石头
阿里云中mysql数据库被攻击了,最终数据找回来了
Build your own website (17)
Taro2.* 小程序配置分享微信朋友圈
第三方跳转网站 出现 405 Method Not Allowed
接收用户输入,身高BMI体重指数检测小业务入门案例
Tensorflow 1.14 specify GPU running settings
Rainstorm effect in levels - ue5
动态规划思想《从入门到放弃》
云呐|工单管理软件,工单管理软件APP
交叉验证如何防止过拟合
剑指 Offer II 035. 最小时间差-快速排序加数据转换
Pytorch中torch和torchvision的安装