当前位置:网站首页>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;
}
边栏推荐
- 云呐-工单管理制度及流程,工单管理规范
- NEON优化:关于交叉存取与反向交叉存取
- Body mass index program, entry to write dead applet project
- C language - array
- Do you understand this patch of the interface control devaxpress WinForms skin editor?
- HMM 笔记
- Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
- Wood extraction in Halcon
- pyflink的安装和测试
- NEON优化:性能优化常见问题QA
猜你喜欢
[牛客] B-完全平方数
Boot - Prometheus push gateway use
[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)
LLDP兼容CDP功能配置
界面控件DevExpress WinForms皮肤编辑器的这个补丁,你了解了吗?
Gazebo的安装&与ROS的连接
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
Part VI, STM32 pulse width modulation (PWM) programming
Js逆向——捅了【马蜂窝】的ob混淆与加速乐
"Exquisite store manager" youth entrepreneurship incubation camp - the first phase of Shunde market has been successfully completed!
随机推荐
boot - prometheus-push gateway 使用
736. Lisp 语法解析 : DFS 模拟题
SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
Taro中添加小程序 “lazyCodeLoading“: “requiredComponents“,
Installation of torch and torch vision in pytorch
Informatics Orsay Ibn YBT 1172: find the factorial of n within 10000 | 1.6 14: find the factorial of n within 10000
Segmenttree
如何管理分布式团队?
Case development of landlord fighting game
golang中的Mutex原理解析
安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
云呐|工单管理软件,工单管理软件APP
Data type of pytorch tensor
力扣1037. 有效的回旋镖
Force buckle 1037 Effective boomerang
C language - array
2022 Google CTF SEGFAULT LABYRINTH wp
分享一个通用的so动态库的编译方法
Gnet: notes on the use of a lightweight and high-performance go network framework