给定一个 24 小时制(小时:分钟 “HH:MM”)的时间列表,找出列表中任意两个时间的最小时间差并以分钟数表示。
let getMinutes = (t) => {
return ((t[0].charCodeAt() - '0'.charCodeAt()) * 10 + (t[1].charCodeAt() - '0'.charCodeAt())) * 60 + (t[3].charCodeAt() - '0'.charCodeAt()) * 10 + (t[4].charCodeAt() - '0'.charCodeAt());
}
var findMinDifference = function(timePoints) {
if(timePoints.length > 1440) {
return 0;
}
timePoints = timePoints.sort((x, y) => getMinutes(x) - getMinutes(y));
let minValue = Number.MAX_VALUE;
let pValue = getMinutes(timePoints[0])
let tValue = pValue;
for(let i = 1; i < timePoints.length; i++) {
const minutes = getMinutes(timePoints[i]);
minValue = Math.min(minValue, minutes - pValue);
pValue = minutes;
}
minValue = Math.min(minValue, tValue + 1440 - pValue)
return minValue
};```