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. 当PowerDesigner的工具栏不见时候该怎么调出来

    当PowerDesigner的工具栏不见时候该怎么调出来,如下所示:选中[Palette]便可

  2. Spring Tool Suite(STS)基本安装配置

    下载jar包:https://spring.io/tools 下载完成后 打开所在文件夹 执行命令行 jar -jar  下载的jar包文件名 然后会自动解压 双击打开软件 配置主面板窗口 配置好之后 ...

  3. qt5之使用QtXlsxWriter库

    note Qt version: 5.12 platform: os x 10.15 本文将介绍直接使用QtXlsxWriter源码 准备 下载QtXlsxWriter 使用Qt Creator 创建 ...

  4. nanogui源码编译+下载

    MAC 没电了,哎..... 只能使用windows10将就了.    截至目前,我已经找到了两个nanogui项目,都是大佬. 分别为: A.https://github.com/dalerank/ ...

  5. 【LeetCode】53. Maximum Subarray 最大子序和 解题报告(Python & C++ & Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力解法 动态规划 日期 题目地址: https:/ ...

  6. 【LeetCode】229. Majority Element II 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 hashmap统计次数 摩尔投票法 Moore Vo ...

  7. 【LeetCode】260. Single Number III 解题报告(Python & C++)

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

  8. Chapter 7 Confounding

    目录 7.1 The structure of confounding Confounding and exchangeability Confounding and the backdoor cri ...

  9. Proximal Algorithms 1 介绍

    目录 定义 解释 图形解释 梯度解释 一个简单的例子 Proximal Algorithms 定义 令\(f: \mathrm{R}^n \rightarrow \mathrm{R} \cup \{+ ...

  10. javaScript系列 [43]-TS、Class and ES5

    本文讨论Typescript中的Class同ES5构造函数的对应关系,涉及TypeScript的诸多语法.构造函数.面向对象以及原型对象等相关知识点细节,本文只简单对比并不进行深入展开. TypeSc ...