Minimum Time Difference LeetCode solution in Python

1
class Solution:
2
def findMinDifference(self, timePoints: List[str]) -> int:
3
# Convert time points to minutes since midnight and sort the list
4
minutes = sorted([int(time[:2]) * 60 + int(time[3:]) for time in timePoints])
5

6
# Calculate the minimum difference between adjacent time points
7
min_diff = float("inf")
8
for i in range(len(minutes) - 1):
9
diff = minutes[i + 1] - minutes[i]
10
if diff < min_diff:
11
min_diff = diff
12

13
# Calculate the difference between the first and last time points
14
diff = (24 * 60 - minutes[-1] + minutes[0]) % (24 * 60)
15
if diff < min_diff:
16
min_diff = diff
17

18
return min_diff

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0