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. JAVA字符串去掉html代码,获取内容

    有时候我们需要在html代码中获取到文本内容,需要把html代码中的标签过滤掉 String htmlStr="html代码"; htmlStr = htmlStr.replace ...

  2. c/c++实现CRC查表及算法

    说明 CRC被广泛应用到各个领域.足见其厉害之处 本文介绍的是CRC查表法. 拷贝代码即可使用 CRC 的起始值 本来默认是0, 实际生产中遇到过,CRC初始值为0xFFFF, 故将其初始值以参数的形 ...

  3. C. Unfair Poll

    http://codeforces.com/problemset/problem/758/C C. Unfair Poll time limit per test 1 second memory li ...

  4. .NET+Sqlite如何支持加密

    .NET+Sqlite如何支持加密 Sqlite SQLite 来源于公共领域 SQLite Is Public Domain. 确保代码不会受到任何专有或许可内容的污染,没有任何来自互联网上的未知来 ...

  5. Variational Autoencoders and Nonlinear ICA: A Unifying Framework

    目录 概 主要内容 本文的模型 Identifiability Khemakhem I., Kingma D. P., Monti R. P. and Hyv"{a}rinen A. Var ...

  6. springboot单元测试为什么排除junit-vintage-engine

    https://blog.csdn.net/Ber_Bai/article/details/117001443 如果不排除,就需要使用@RunWith注解? 25-springboot整合单元测试指定 ...

  7. Shell调试Debug的三种方式

    Shell脚本进行Debug调试的三种方法如下: 1.在调用脚本的时候开启deubg sh -x shell.sh 2.在脚本文件首行开启deubg #!/bin/bash -x 3. 使用set开启 ...

  8. nginx worker_cpu_affinity使用方法

    Nginx默认没有开启利用多核CPU,我们可以通过增加worker_cpu_affinity配置参数来充分利用多核CPU.CPU是任务处理,计算最关键的资源,CPU核越多,性能就越好. 配置Nginx ...

  9. STM32F3 GPIO的八种模式及工作原理

    一.GPIO简介 GPIO(英语:General-purpose input/output),通用型之输入输出的简称,简单来说就是STM32可控制的引脚,STM32芯片的GPIO引脚与外部设备连接起来 ...

  10. CSS基础 定位相关属性的使用方法

    1.相对定位:position:relative: 属性名:position 属性值:relative: 特点:1.相对自己的位置移动 2.配合方位名词移动,如:top.left.right,bott ...