当前位置:网站首页>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优化:性能优化常见问题QA
- 移植DAC芯片MCP4725驱动到NUC980
- [batch dos-cmd command - summary and summary] - view or modify file attributes (attrib), view and modify file association types (Assoc, ftype)
- Neon Optimization: summary of performance optimization experience
- gnet: 一个轻量级且高性能的 Go 网络框架 使用笔记
- NEON优化:矩阵转置的指令优化案例
- Meet in the middle
- 【JVM调优实战100例】04——方法区调优实战(上)
- Lldp compatible CDP function configuration
- 前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
猜你喜欢
2022 Google CTF SEGFAULT LABYRINTH wp
Send template message via wechat official account
"Exquisite store manager" youth entrepreneurship incubation camp - the first phase of Shunde market has been successfully completed!
Wood extraction in Halcon
[Niuke] b-complete square
免费白嫖的图床对比
Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
Can the system hibernation file be deleted? How to delete the system hibernation file
[Niuke] [noip2015] jumping stone
随机推荐
c语言—数组
[batch dos-cmd command - summary and summary] - view or modify file attributes (attrib), view and modify file association types (Assoc, ftype)
NEON优化:关于交叉存取与反向交叉存取
THREE. AxesHelper is not a constructor
Oracle:CDB限制PDB资源实战
Realize incremental data synchronization between MySQL and ES
Meet in the middle
Make a simple graphical interface with Tkinter
接收用户输入,身高BMI体重指数检测小业务入门案例
Implementation principle of waitgroup in golang
2022 Google CTF SEGFAULT LABYRINTH wp
Force buckle 1037 Effective boomerang
Taro2.* applet configuration sharing wechat circle of friends
Niuke cold training camp 6B (Freund has no green name level)
Windows installation mysql8 (5 minutes)
资产安全问题或制约加密行业发展 风控+合规成为平台破局关键
Js逆向——捅了【马蜂窝】的ob混淆与加速乐
Dynamic planning idea "from getting started to giving up"
Part VI, STM32 pulse width modulation (PWM) programming
[case sharing] basic function configuration of network loop detection