File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 103
103
| 515| [ 在每个树行中找最大值] ( https://leetcode.cn/problems/find-largest-value-in-each-tree-row/ ) | [ JavaScript] ( ./algorithms/find-largest-value-in-each-tree-row.js ) | Medium|
104
104
| 520| [ 检测大写字母] ( https://leetcode.cn/problems/detect-capital/ ) | [ JavaScript] ( ./algorithms/detect-capital.js ) | Easy|
105
105
| 535| [ TinyURL 的加密与解密] ( https://leetcode.cn/problems/encode-and-decode-tinyurl/ ) | [ JavaScript] ( ./algorithms/encode-and-decode-tinyurl.js ) | Medium|
106
+ | 539| [ 最小时间差] ( https://leetcode.cn/problems/minimum-time-difference/ ) | [ JavaScript] ( ./algorithms/minimum-time-difference.js ) | Medium|
106
107
| 541| [ 反转字符串 II] ( https://leetcode.cn/problems/reverse-string-ii/ ) | [ JavaScript] ( ./algorithms/reverse-string-ii.js ) | Easy|
107
108
| 543| [ 二叉树的直径] ( https://leetcode.cn/problems/diameter-of-binary-tree/ ) | [ JavaScript] ( ./algorithms/diameter-of-binary-tree.js ) | Easy|
108
109
| 551| [ 学生出勤记录 I] ( https://leetcode.cn/problems/student-attendance-record-i/ ) | [ JavaScript] ( ./algorithms/student-attendance-record-i.js ) | Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string[] } timePoints
3
+ * @return {number }
4
+ */
5
+ var findMinDifference = function ( timePoints ) {
6
+ let min = Number . MAX_VALUE ;
7
+ const arr = [ ] ;
8
+ // 转换为分钟
9
+ for ( let item of timePoints ) {
10
+ const [ hour , minute ] = item . split ( ":" ) ;
11
+ arr . push ( Number ( hour ) * 60 + Number ( minute ) ) ;
12
+ }
13
+ arr . sort ( ( a , b ) => a - b ) ;
14
+
15
+ for ( let i = 1 ; i < arr . length ; i ++ ) {
16
+ min = Math . min ( min , arr [ i ] - arr [ i - 1 ] ) ;
17
+ }
18
+ // 首尾再比较一次
19
+ min = Math . min ( min , 24 * 60 - arr [ arr . length - 1 ] + arr [ 0 ] ) ;
20
+
21
+ return min ;
22
+ } ;
You can’t perform that action at this time.
0 commit comments