给定一个 24 小时制(小时:分钟)的时间列表,找出列表中任意两个时间的最小时间差并已分钟数表示。
示例 1:
输入: ["23:59","00:00"]
输出: 1
备注:
    1.列表中时间数在 2~20000 之间。
    2.每个时间取值在 00:00~23:59 之间。
详见:https://leetcode.com/problems/minimum-time-difference/description/
C++:

class Solution {
public:
int findMinDifference(vector<string>& timePoints)
{
int res = INT_MAX, n = timePoints.size(), diff = 0;
sort(timePoints.begin(), timePoints.end());
for (int i = 0; i < n; ++i)
{
string t1 = timePoints[i], t2 = timePoints[(i + 1) % n];
int h1 = (t1[0] - '0') * 10 + t1[1] - '0';
int m1 = (t1[3] - '0') * 10 + t1[4] - '0';
int h2 = (t2[0] - '0') * 10 + t2[1] - '0';
int m2 = (t2[3] - '0') * 10 + t2[4] - '0';
diff = (h2 - h1) * 60 + (m2 - m1);
if (i == n - 1)
{
diff += 24 * 60;
}
res = min(res, diff);
}
return res;
}
};

参考:http://www.cnblogs.com/grandyang/p/6568398.html

539 Minimum Time Difference 最小时间差的更多相关文章

  1. 539. Minimum Time Difference

    Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...

  2. LC 539. Minimum Time Difference

    Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...

  3. 【LeetCode】539. Minimum Time Difference 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/minimum-t ...

  4. [LeetCode] Minimum Time Difference 最短时间差

    Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...

  5. Python解Leetcode: 539. Minimum Time Difference

    题目描述:给定一个由时间字符组成的列表,找出任意两个时间之间最小的差值. 思路: 把给定的链表排序,并且在排序的同时把60进制的时间转化成十进制整数: 遍历排序的数组,求出两个相邻值之间的差值: 求出 ...

  6. [Swift]LeetCode539. 最小时间差 | Minimum Time Difference

    Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...

  7. LeetCode 530. Minimum Absolute Difference in BST (二叉搜索树中最小绝对差)

    Given a binary search tree with non-negative values, find the minimum absolute difference between va ...

  8. [LeetCode] Minimum Absolute Difference in BST 二叉搜索树的最小绝对差

    Given a binary search tree with non-negative values, find the minimum absolute difference between va ...

  9. [Swift]LeetCode530. 二叉搜索树的最小绝对差 | Minimum Absolute Difference in BST

    Given a binary search tree with non-negative values, find the minimum absolute difference between va ...

随机推荐

  1. Appium——解决每次启动时都安装setting和unlock app方法

    找到appium安装目录 C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android 修改代码,注释掉弹出setting ...

  2. haproxy参数解析

    HAProxy工作于隧道模式,其仅检查每一个连接的第一个请求, 1. option abortonclose #当服务器负载过高时,将自动关闭队列中处理时间较长的连接请求 2. option http ...

  3. js中的命名空间

    尽量不要使用全局变量,防止环境污染和命名冲突. 所以,将全局变量放在一个命名空间下,是一个好的解决方案. 静态命名空间 1. 直接赋值 这是最基本的方法,但是它很啰嗦,你得重复书写多次变量名.好处是它 ...

  4. (转)vim 访问系统剪贴板

    原文出处:http://vim.wikia.com/wiki/Accessing_the_system_clipboard Please review this tip: This tip was i ...

  5. distutils 打包setup.py

    from distutils.core import setup setup(name='hello', version='1.0', description='test example', auth ...

  6. MongoDB监控之一:运行状态、性能监控,分析

    为什么要监控? 监控及时获得应用的运行状态信息,在问题出现时及时发现. 监控什么? CPU.内存.磁盘I/O.应用程序(MongoDB).进程监控(ps -aux).错误日志监控 1.4.1 Mong ...

  7. JS-React:目录

    ylbtech-JS-React:目录 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbt ...

  8. having,groub by 结合聚合函数的用法解析

    聚合函数有:sum , count, avg, max等等: where无法与聚合函数一起使用,所以在sql语句中加上having子句来筛选查询结果: 上面的sql语句是错的,正确如下: SELECT ...

  9. seafile文档

    https://manual-cn.seafile.com/deploy_windows/download_and_setup_seafile_windows_server.html

  10. P-Function

    题意: 对于集合 $S = {1, 2, ...., n}$ , 定义函数 $F(x) = y, x, y$ 属于 $S$,对于任何 $x$ 属于 $S$, 有 $F(F...F(x)) = x$, ...