539. Minimum Time Difference
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格式的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的更多相关文章
- LC 539. Minimum Time Difference
Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...
- 【LeetCode】539. Minimum Time Difference 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/minimum-t ...
- 539 Minimum Time Difference 最小时间差
给定一个 24 小时制(小时:分钟)的时间列表,找出列表中任意两个时间的最小时间差并已分钟数表示.示例 1:输入: ["23:59","00:00"]输出: 1 ...
- Python解Leetcode: 539. Minimum Time Difference
题目描述:给定一个由时间字符组成的列表,找出任意两个时间之间最小的差值. 思路: 把给定的链表排序,并且在排序的同时把60进制的时间转化成十进制整数: 遍历排序的数组,求出两个相邻值之间的差值: 求出 ...
- 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 ...
- LeetCode 530. Minimum Absolute Difference in BST (二叉搜索树中最小绝对差)
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
- 530. Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
- [LeetCode] Minimum Time Difference 最短时间差
Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...
- [LeetCode] Minimum Absolute Difference in BST 二叉搜索树的最小绝对差
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
随机推荐
- Python的 垃圾回收机制
垃圾回收 1. 小整数对象池 整数在程序中的使用非常广泛,Python为了优化速度,使用了小整数对象池, 避免为整数频繁申请和销毁内存空间. Python 对小整数的定义是 [-5, 257) 这些整 ...
- Chrome导出导入书签
Chrome导出标签 Chrome导入书签
- 【LeetCode】326. Power of Three 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 循环 递归 取对数 判断是不是最大3的倍数的因子 日 ...
- 【LeetCode】257. Binary Tree Paths 解题报告(java & python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leet ...
- 【LeetCode】382. Linked List Random Node 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数组保存再随机选择 蓄水池抽样 日期 题目地址:ht ...
- P1753HackSon的趣味题
1 #include<stdio.h> 2 #include<algorithm> 3 #include<iostream> 4 #include<stdli ...
- anaconda 命令小览
一 查看conda环境中安装了什么库: conda list 参考文献: 怎么查看anaconda安装了什么库?-Python学习网
- Scalable Rule-Based Representation Learning for Interpretable Classification
目录 概 主要内容 Wang Z., Zhang W., Liu N. and Wang J. Scalable rule-based representation learning for inte ...
- Learning a Similarity Metric Discriminatively, with Application to Face Verification
目录 概 主要内容 genuine 和 impostor 文1 文2 Chopra S, Hadsell R, Lecun Y, et al. Learning a similarity metric ...
- On the Optimization of Deep Networks: Implicit Acceleration by Overparameterization
目录 引 主要内容 定理1 Claim 1 Claim 2 定理2 证明 定理1的证明 Claim 1 的证明 Kronecker product (克罗内克积) Theorem 2 的证明 代码 A ...