当前位置:网站首页>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;
}
边栏推荐
- C language - array
- from .cv2 import * ImportError: libGL.so.1: cannot open shared object file: No such file or direc
- [batch dos-cmd command - summary and summary] - view or modify file attributes (attrib), view and modify file association types (Assoc, ftype)
- Eventbus source code analysis
- Transformation transformation operator
- Taro中添加小程序 “lazyCodeLoading“: “requiredComponents“,
- 从零开始匹配vim(0)——vimscript 简介
- Spark TPCDS Data Gen
- table表格设置圆角
- THREE. AxesHelper is not a constructor
猜你喜欢
![[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)

微信公众号发送模板消息
![[HFCTF2020]BabyUpload session解析引擎](/img/db/6003129bc16f943ad9868561a2d5dc.png)
[HFCTF2020]BabyUpload session解析引擎

Make Jar, Not War

Maidong Internet won the bid of Beijing life insurance to boost customers' brand value

线段树(SegmentTree)

C language - array

第三方跳转网站 出现 405 Method Not Allowed

Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which

Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
随机推荐
Windows installation mysql8 (5 minutes)
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?
Eventbus source code analysis
Informatics Olympiad YBT 1171: factors of large integers | 1.6 13: factors of large integers
「笔记」折半搜索(Meet in the Middle)
斗地主游戏的案例开发
2022 Google CTF SEGFAULT LABYRINTH wp
Wood extraction in Halcon
MySQL中回表的代价
[batch dos-cmd command - summary and summary] - view or modify file attributes (attrib), view and modify file association types (Assoc, ftype)
移植DAC芯片MCP4725驱动到NUC980
Receive user input, height BMI, BMI detection small business entry case
JTAG principle of arm bare board debugging
分享一个通用的so动态库的编译方法
2022 Google CTF segfault Labyrinth WP
Neon Optimization: About Cross access and reverse cross access
Neon Optimization: performance optimization FAQ QA
405 method not allowed appears when the third party jumps to the website
Meet in the middle
从零开始匹配vim(0)——vimscript 简介