当前位置:网站首页>剑指 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;
}
边栏推荐
- C # method of calculating lunar calendar date 2022
- [batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
- Windows installation mysql8 (5 minutes)
- boot - prometheus-push gateway 使用
- Deep learning framework TF installation
- Atomic in golang, and cas Operations
- 斗地主游戏的案例开发
- tensorflow 1.14指定gpu运行设置
- 从零开始匹配vim(0)——vimscript 简介
- Supersocket 1.6 creates a simple socket server with message length in the header
猜你喜欢
Maidong Internet won the bid of Beijing life insurance to boost customers' brand value
2022 Google CTF SEGFAULT LABYRINTH wp
HMM 笔记
Boot - Prometheus push gateway use
[HFCTF2020]BabyUpload session解析引擎
BFS realizes breadth first traversal of adjacency matrix (with examples)
Periodic flash screen failure of Dell notebook
Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
Gazebo的安装&与ROS的连接
Dell Notebook Periodic Flash Screen Fault
随机推荐
树莓派/arm设备上安装火狐Firefox浏览器
Data type of pytorch tensor
Deep learning framework TF installation
pytorch之数据类型tensor
【JVM调优实战100例】04——方法区调优实战(上)
Provincial and urban level three coordinate boundary data CSV to JSON
Building a dream in the digital era, the Xi'an station of the city chain science and Technology Strategy Summit ended smoothly
[牛客] [NOIP2015]跳石头
[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)
Batch obtain the latitude coordinates of all administrative regions in China (to the county level)
736. Lisp 语法解析 : DFS 模拟题
NEON优化:性能优化常见问题QA
NEON优化:关于交叉存取与反向交叉存取
MySQL script batch queries all tables containing specified field types in the database
Neon Optimization: summary of performance optimization experience
The difference between spin and sleep
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such
What are the differences between Oracle Linux and CentOS?
Can the system hibernation file be deleted? How to delete the system hibernation file
Niuke cold training camp 6B (Freund has no green name level)