当前位置:网站首页>剑指 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;
}
边栏推荐
- Installation of gazebo & connection with ROS
- Body mass index program, entry to write dead applet project
- Taro2.* 小程序配置分享微信朋友圈
- JTAG principle of arm bare board debugging
- Transformation transformation operator
- Anfulai embedded weekly report no. 272: 2022.06.27--2022.07.03
- C # method of calculating lunar calendar date 2022
- golang中的WaitGroup实现原理
- [JS] obtain the N days before and after the current time or the n months before and after the current time (hour, minute, second, year, month, day)
- 如何管理分布式团队?
猜你喜欢

2022 Google CTF SEGFAULT LABYRINTH wp

Lldp compatible CDP function configuration

Chenglian premium products has completed the first step to enter the international capital market by taking shares in halber international

Tensorflow GPU installation

Boot - Prometheus push gateway use

Part V: STM32 system timer and general timer programming

Body mass index program, entry to write dead applet project

Force buckle 1037 Effective boomerang

字节P7专业级讲解:接口测试常用工具及测试方法,福利文

阿里云中mysql数据库被攻击了,最终数据找回来了
随机推荐
Part VI, STM32 pulse width modulation (PWM) programming
动态规划思想《从入门到放弃》
How to manage distributed teams?
What are the differences between Oracle Linux and CentOS?
2022 Google CTF SEGFAULT LABYRINTH wp
Eventbus source code analysis
golang中的atomic,以及CAS操作
实现mysql与ES的增量数据同步
自旋与sleep的区别
docker 方法安装mysql
BFS realizes breadth first traversal of adjacency matrix (with examples)
HMM notes
Implementation principle of waitgroup in golang
C# 计算农历日期方法 2022
Rainstorm effect in levels - ue5
from .cv2 import * ImportError: libGL.so.1: cannot open shared object file: No such file or direc
SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
Tensorflow 1.14 specify GPU running settings
Maidong Internet won the bid of Beijing life insurance to boost customers' brand value
Spark TPCDS Data Gen