Skip to content

Commit d1af13e

Browse files
committedMar 5, 2025
Add solution #539
1 parent ce55ae4 commit d1af13e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@
429429
532|[K-diff Pairs in an Array](./0532-k-diff-pairs-in-an-array.js)|Medium|
430430
537|[Complex Number Multiplication](./0537-complex-number-multiplication.js)|Medium|
431431
538|[Convert BST to Greater Tree](./0538-convert-bst-to-greater-tree.js)|Medium|
432+
539|[Minimum Time Difference](./0539-minimum-time-difference.js)|Medium|
432433
541|[Reverse String II](./0541-reverse-string-ii.js)|Easy|
433434
542|[01 Matrix](./0542-01-matrix.js)|Medium|
434435
543|[Diameter of Binary Tree](./0543-diameter-of-binary-tree.js)|Easy|
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* 539. Minimum Time Difference
3+
* https://leetcode.com/problems/minimum-time-difference/
4+
* Difficulty: Medium
5+
*
6+
* Given a list of 24-hour clock time points in "HH:MM" format, return the minimum minutes
7+
* difference between any two time-points in the list.
8+
*/
9+
10+
/**
11+
* @param {string[]} timePoints
12+
* @return {number}
13+
*/
14+
var findMinDifference = function(timePoints) {
15+
const minutes = timePoints.map(time => {
16+
const [h, m] = time.split(':').map(Number);
17+
return h * 60 + m;
18+
}).sort((a, b) => a - b);
19+
let diff = Infinity;
20+
21+
for (let i = 1; i < minutes.length; i++) {
22+
diff = Math.min(diff, minutes[i] - minutes[i - 1]);
23+
}
24+
25+
return Math.min(diff, 1440 - minutes[minutes.length - 1] + minutes[0]);
26+
};

0 commit comments

Comments
 (0)
Please sign in to comment.