-
Notifications
You must be signed in to change notification settings - Fork 70
/
res.js
40 lines (34 loc) · 859 Bytes
/
res.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* @param {string[]} timePoints
* @return {number}
*/
let findMinDifference = function(timePoints) {
let len = timePoints.length;
if (len === 1) return 0;
let tarray = new Array(24*60),
min = 1441,
max = -1,
res = 1441,
prev = 0;
for (let i=0; i<len; i++) {
let tmplist = timePoints[i].split(':'),
minute = (tmplist[0]-'0')*60 + (tmplist[1]-'0');
if (tarray[minute]) {
return 0;
} else {
tarray[minute] = true;
}
}
for (let i=0; i<1440; i++) {
if (tarray[i]) {
if (min !== 1441) {
res = Math.min(res, i-prev);
} else {
min = i;
}
max = Math.max(max, i);
prev = i;
}
}
return Math.min(res, 24*60-max+min);
};