leetcode--539. Minimum Time Difference
Posted 孤独风中一匹狼
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode--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"]
const MaxMinute = 24 * 60 func findMinDifference(slice1 []string) int { min := MaxMinute ts := make([]int, 2*MaxMinute) for _, v := range slice1 { ts[getMinute(v)] ++ if ts[getMinute(v)]==2{ return 0 } ts[getMinute(v)+MaxMinute]++ } front, rear := 0, 0 for front < MaxMinute*2 { if front == rear || ts[front] == 0 { front++ continue } if ts[rear] == 0 { rear++ continue } if min > front-rear { min = front - rear } rear = front front ++ } return min } func getMinute(timestr string) int { return ((int(timestr[0]-‘0‘))*10+int(timestr[1]-‘0‘))*60+(int(timestr[3]-‘0‘))*10+int(timestr[4]-‘0‘) }
Output: 1
以上是关于leetcode--539. Minimum Time Difference的主要内容,如果未能解决你的问题,请参考以下文章