1. 程式人生 > >leetcode--539. Minimum Time Difference

leetcode--539. Minimum Time Difference

lee bsp ron hour output spa int NPU clas

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