[leetcode] 539. Minimum Time Difference

网友投稿 238 2022-09-15

[leetcode] 539. Minimum Time Difference

Description

Given a list of 24-hour clock time points in “Hour:Minutes” format, find the minimum minutes difference between any two time points in the list. Example 1:

Input: ["23:59","00:00"]Output: 1

Note:

The number of time points in the given list is at least 2 and won’t exceed 20000.The input time is legal and ranges from 00:00 to 23:59.

分析

题目的意思是:给你一个时刻数组,找出其中的最小时间差。

最简单直接的办法就是给数组排序,这样时间点小的就在前面了,然后我们分别把小时和分钟提取出来,计算差值,注意唯一的特殊情况就是第一个和末尾的时间点进行比较,第一个时间点需要加上24小时再做差值.

代码

class Solution {public: int findMinDifference(vector& timePoints) { int res=INT_MAX; int n=timePoints.size(); sort(timePoints.begin(),timePoints.end()); for(int i=0;i

参考文献

​​[LeetCode] Minimum Time Difference 最短时间差​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:[leetcod] 12. Integer to Roman
下一篇:丁道师:引入国资共享发展红利 苏宁开启向新而生之旅!
相关文章

 发表评论

暂时没有评论,来抢沙发吧~