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:

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

题目含义:给定一定24格式的Hour:Minutes字符,找到任意两个时间点的最小时间差

 1     public int findMinDifference(List<String> timePoints) {
2 boolean[] minutes = new boolean[24 * 60];
3 for (String time : timePoints) {
4 String[] values = time.split(":");
5 int minute = Integer.valueOf(values[0]) * 60 + Integer.valueOf(values[1]);
6 if (minutes[minute]) return 0;
7 minutes[minute] = true;
8 }
9 int min = Integer.MAX_VALUE, left = Integer.MAX_VALUE, right = Integer.MIN_VALUE;
10 int previous = 0;//上一个时间值
11 for (int i = 0; i < minutes.length; i++) {
12 if (!minutes[i]) continue;
13 if (left != Integer.MAX_VALUE) {
14 min = Math.min(min, i - previous);//min记录了最小的时间差
15 }
16 left = Math.min(left, i);//距离零点最近的点
17 right = Math.max(right, i);//距离零点最远的点
18 previous = i;
19 }
20 return Math.min(min, 24 * 60 - right + left);
21 }

539. Minimum Time Difference的更多相关文章

  1. LC 539. Minimum Time Difference

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

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

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

  3. 539 Minimum Time Difference 最小时间差

    给定一个 24 小时制(小时:分钟)的时间列表,找出列表中任意两个时间的最小时间差并已分钟数表示.示例 1:输入: ["23:59","00:00"]输出: 1 ...

  4. Python解Leetcode: 539. Minimum Time Difference

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

  5. 51. leetcode 530. Minimum Absolute Difference in BST

    530. Minimum Absolute Difference in BST Given a binary search tree with non-negative values, find th ...

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

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

  7. 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 Time Difference 最短时间差

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

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

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

随机推荐

  1. 【LeetCode】1110. Delete Nodes And Return Forest 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcode ...

  2. hud -5124-lines(线段树)

    题目的意思是求重合层数最多的段(把点也看成段). 给的数据范围为N<1e5; ai<1e9; 有于N只有1e5;那么离散化一下可以将ai的范围映射到1e5,而不改变原端点的相对大小. 接下 ...

  3. 初识TMMi——测试成熟度模型集成

    利用零碎的时间,粗略了解了一下TMMi V1.2,整理一下学习笔记跟大家分享一下. 本文分为四个部分,分别为TMMi概述.TMMi结构.成熟度级别和过程域.TMMi实施周期,希望能够帮助大家更好的理解 ...

  4. @Transactional 注解实现

    @Transactional注解简介 @Transactional是spring中声明式事务管理的注解配置方式,相信这个注解的作用大家都很清楚.@Transactional注解可以帮助我们把事务开启. ...

  5. 「算法笔记」旋转 Treap

    一.引入 随机数据中,BST 一次操作的期望复杂度为 \(\mathcal{O}(\log n)\). 然而,BST 很容易退化,例如在 BST 中一次插入一个有序序列,将会得到一条链,平均每次操作的 ...

  6. springboot中word转pdf,加盖电子印章

    概述 在开发过程中,word转pdf的方式有很多种有jar包的方式,有安装openoffice的方式,但是使用有的jar包有license认证,不然会生成水印,综合几种方法我采用了libreoffic ...

  7. CS5211替代兼容PS8625|DP转LVDS|CS5211设计方案详解

    PS8625是一个DP显示端口 到LVDS转换器芯片,利用GPU和显示端口(DP) 或嵌入式显示端口(eDP) 输出和接受LVDS输入的显示面板.PS8625实现双通道DP输入,双链路LVDS输出.P ...

  8. 应用TYPE-C外围电源管理IC IM2605

    应用于TYPE-C外围集成同步4开关Buck-Boost变换器的电源管理IC   IM2605 IM2605描述 IM2605集成了一个同步4开关Buck-Boost变换器,在输入电压小于或大于输出电 ...

  9. 【jvm】03-写了final就是常量池了么

    [jvm]03-写了final就是常量池了么 欢迎关注b站账号/公众号[六边形战士夏宁],一个要把各项指标拉满的男人.该文章已在github目录收录. 屏幕前的大帅比和大漂亮如果有帮助到你的话请顺手点 ...

  10. Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面

    效果图: 自定义对话框布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xml ...