Problem
Given a list of 24-hour clock time points in “HH:MM” format, return the minimum minutes difference between any two time-points in the list.Examples
Constraints
2 <= timePoints.length <= 2 * 10^4timePoints[i]is in the format “HH:MM”.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Tested Python solution for LeetCode 539 with 15 pytest cases. Generate a practice environment with lcpy.
lcpy gen -n 539 # by problem number
lcpy gen -s minimum_time_difference # by problem name
Input: timePoints = ["23:59","00:00"]
Output: 1
Input: timePoints = ["00:00","23:59","00:00"]
Output: 0
2 <= timePoints.length <= 2 * 10^4timePoints[i] is in the format “HH:MM”.class Solution:
# Time: O(n log n)
# Space: O(n)
def find_min_difference(self, time_points: list[str]) -> int:
minutes = sorted(int(t[:2]) * 60 + int(t[3:]) for t in time_points)
best = 24 * 60 - (minutes[-1] - minutes[0])
for i in range(len(minutes) - 1):
best = min(best, minutes[i + 1] - minutes[i])
return best
| Time | Space |
|---|---|
| O(n log n) | O(n) |