题目:
题解:
class Solution {
public int findMinDifference(List<String> timePoints) {
if(timePoints.size()>1440){
return 0;
}
Collections.sort(timePoints);
int minutesO = getMinutes(timePoints.get(0));
int nextMinutes = minutesO;
int min = getMinutes(timePoints.get(1))-getMinutes(timePoints.get(0));
for(int i=1;i<timePoints.size();i++){
min = Math.min(min, getMinutes(timePoints.get(i))-nextMinutes);
nextMinutes = getMinutes(timePoints.get(i));
}
int ans = minutesO + 1440 - nextMinutes;
return Math.min(ans,min);
}
//字符串转分钟
private int getMinutes(String timePoint){
return (timePoint.charAt(0)-'0')*10*60+(timePoint.charAt(1)-'0')*60+(timePoint.charAt(3)-'0')*10+(timePoint.charAt(4)-'0');
}
}
性能指标: