当前位置:网站首页>剑指 Offer II 035. 最小时间差-快速排序加数据转换
剑指 Offer II 035. 最小时间差-快速排序加数据转换
2022-07-06 17:36:00 【Mr Gao】
剑指 Offer II 035. 最小时间差-快速排序加数据转换
给定一个 24 小时制(小时:分钟 “HH:MM”)的时间列表,找出列表中任意两个时间的最小时间差并以分钟数表示。
示例 1:
输入:timePoints = [“23:59”,“00:00”]
输出:1
示例 2:
输入:timePoints = [“00:00”,“23:59”,“00:00”]
输出:0
解题代码如下:
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;
}
边栏推荐
- 负载均衡性能参数如何测评?
- 让我们,从头到尾,通透网络I/O模型
- 736. Lisp 语法解析 : DFS 模拟题
- HMM 笔记
- Dynamic planning idea "from getting started to giving up"
- Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
- LLDP兼容CDP功能配置
- Installation of gazebo & connection with ROS
- 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?
- Installation of torch and torch vision in pytorch
猜你喜欢

线段树(SegmentTree)

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

pytorch之数据类型tensor

Building a dream in the digital era, the Xi'an station of the city chain science and Technology Strategy Summit ended smoothly

如何管理分布式团队?

Telerik UI 2022 R2 SP1 Retail-Not Crack

阿里云中mysql数据库被攻击了,最终数据找回来了

Transformation transformation operator

免费白嫖的图床对比
![[100 cases of JVM tuning practice] 04 - Method area tuning practice (Part 1)](/img/7a/bd03943c39d3f731afb51fe2e0f898.png)
[100 cases of JVM tuning practice] 04 - Method area tuning practice (Part 1)
随机推荐
table表格设置圆角
Let's see through the network i/o model from beginning to end
线段树(SegmentTree)
实现mysql与ES的增量数据同步
Activereportsjs 3.1 Chinese version | | | activereportsjs 3.1 English version
Building a dream in the digital era, the Xi'an station of the city chain science and Technology Strategy Summit ended smoothly
Eventbus source code analysis
Build your own website (17)
Anfulai embedded weekly report no. 272: 2022.06.27--2022.07.03
go-zero微服务实战系列(九、极致优化秒杀性能)
Spark TPCDS Data Gen
【JVM调优实战100例】05——方法区调优实战(下)
[case sharing] basic function configuration of network loop detection
Neon Optimization: summary of performance optimization experience
云呐|工单管理办法,如何开展工单管理
golang中的atomic,以及CAS操作
微信公众号发送模板消息
2022 Google CTF segfault Labyrinth WP
接收用户输入,身高BMI体重指数检测小业务入门案例
Force buckle 1037 Effective boomerang