Skip to content

Commit 54bcf48

Browse files
committed
[LeetCode Sync] Runtime - 8 ms (71.83%), Memory - 20.4 MB (55.18%)
1 parent be0b658 commit 54bcf48

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Given a list of 24-hour clock time points in <strong>&quot;HH:MM&quot;</strong> format, return <em>the minimum <b>minutes</b> difference between any two time-points in the list</em>.
2+
<p>&nbsp;</p>
3+
<p><strong class="example">Example 1:</strong></p>
4+
<pre><strong>Input:</strong> timePoints = ["23:59","00:00"]
5+
<strong>Output:</strong> 1
6+
</pre><p><strong class="example">Example 2:</strong></p>
7+
<pre><strong>Input:</strong> timePoints = ["00:00","23:59","00:00"]
8+
<strong>Output:</strong> 0
9+
</pre>
10+
<p>&nbsp;</p>
11+
<p><strong>Constraints:</strong></p>
12+
13+
<ul>
14+
<li><code>2 &lt;= timePoints.length &lt;= 2 * 10<sup>4</sup></code></li>
15+
<li><code>timePoints[i]</code> is in the format <strong>&quot;HH:MM&quot;</strong>.</li>
16+
</ul>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution:
2+
def findMinDifference(self, timePoints: List[str]) -> int:
3+
sorted_timePoints = sorted(int(val[:2]) * 60 + int(val[3:]) for val in timePoints)
4+
sorted_timePoints.append(sorted_timePoints[0] + 1440)
5+
6+
return min(val2 - val1 for val1, val2 in pairwise(sorted_timePoints))

0 commit comments

Comments
 (0)