File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 429
429
532|[ K-diff Pairs in an Array] ( ./0532-k-diff-pairs-in-an-array.js ) |Medium|
430
430
537|[ Complex Number Multiplication] ( ./0537-complex-number-multiplication.js ) |Medium|
431
431
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|
432
433
541|[ Reverse String II] ( ./0541-reverse-string-ii.js ) |Easy|
433
434
542|[ 01 Matrix] ( ./0542-01-matrix.js ) |Medium|
434
435
543|[ Diameter of Binary Tree] ( ./0543-diameter-of-binary-tree.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments