当前位置:网站首页>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;
}
边栏推荐
- Let's see through the network i/o model from beginning to end
- Supersocket 1.6 creates a simple socket server with message length in the header
- NEON优化:log10函数的优化案例
- 【JVM调优实战100例】04——方法区调优实战(上)
- from .cv2 import * ImportError: libGL.so.1: cannot open shared object file: No such file or direc
- Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
- 【JVM调优实战100例】05——方法区调优实战(下)
- 自旋与sleep的区别
- Taro applet enables wxml code compression
- Data type of pytorch tensor
猜你喜欢

C language - array
![[HFCTF2020]BabyUpload session解析引擎](/img/db/6003129bc16f943ad9868561a2d5dc.png)
[HFCTF2020]BabyUpload session解析引擎

Send template message via wechat official account

Dynamic planning idea "from getting started to giving up"

【JVM调优实战100例】04——方法区调优实战(上)

LLDP兼容CDP功能配置

JTAG debugging experience of arm bare board debugging

线段树(SegmentTree)

Segmenttree

Transformation transformation operator
随机推荐
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?
UI control telerik UI for WinForms new theme - vs2022 heuristic theme
from . cv2 import * ImportError: libGL. so. 1: cannot open shared object file: No such file or direc
There is an error in the paddehub application
MySQL script batch queries all tables containing specified field types in the database
Tensorflow 1.14 specify GPU running settings
Table table setting fillet
HMM notes
安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
分享一个通用的so动态库的编译方法
[Niuke] b-complete square
gnet: 一个轻量级且高性能的 Go 网络框架 使用笔记
【案例分享】网络环路检测基本功能配置
子网划分、构造超网 典型题
实现mysql与ES的增量数据同步
Using the entry level of DVA in taro3.*
Make Jar, Not War
Anfulai embedded weekly report no. 272: 2022.06.27--2022.07.03
Installation of torch and torch vision in pytorch
go-zero微服务实战系列(九、极致优化秒杀性能)