Input: timePoints = ["23:59","00:00"]
Output: 1
Input: timePoints = ["00:00","23:59","00:00"]
Output: 0
func findMinDifference(timePoints []string) int {
sort.Slice(timePoints, func(i int, j int) bool { // εΎ00:00~23:59 ζεΊ
if timePoints[i][0] == timePoints[j][0] && timePoints[i][1] == timePoints[j][1] {
if timePoints[i][3] == timePoints[j][3] {
return timePoints[i][4] < timePoints[j][4]
}
return timePoints[i][3] < timePoints[j][3]
}
if timePoints[i][0] == timePoints[j][0] {
return timePoints[i][1] < timePoints[j][1]
}
return timePoints[i][0] < timePoints[j][0]
})
ans := 100000000000
for i:=1; i<len(timePoints); i++ {
ans = min(ans, timeToMinutes(timePoints[i]) - timeToMinutes(timePoints[i - 1]))
}
// ζ倧ηζιθζε°ηζιδΉιι
ans = min(ans, 1440 - timeToMinutes(timePoints[len(timePoints) - 1]) + timeToMinutes(timePoints[0]))
return ans
}
func timeToMinutes(s string) int { // θ½ζηΊει
month, err := strconv.Atoi(s[:2]) //month
if err != nil {
fmt.Println(err)
}
day, err1 := strconv.Atoi(s[3:]) //day
if err1 != nil {
fmt.Println(err)
}
return month * 60 + day
}
func min(a, b int) int {
if a < b { return a }
return b
}