539. [字符串]最小时间差
// 执行用时: 9 ms , 在所有 Java 提交中击败了 62.23% 的用户
// 内存消耗: 40 MB , 在所有 Java 提交中击败了 58.90% 的用户
class Solution {
public int findMinDifference(List
// 将所有24小时制时间转分钟存入数组
int[] times = new int[timePoints.size()];
int i = 0;
for(String timePoint: timePoints){
times[i] = Integer.parseInt(timePoint.substring(0, 2)) * 60 + Integer.parseInt(timePoint.substring(3, 5));
i++;
}
Arrays.sort(times);
int result = 1440 - times[times.length-1] + times[0];
for (int j = 1; j < times.length; j++) {
result = Math.min(result, times[j] - times[j-1]);
}
return result;
}
}

浙公网安备 33010602011771号