Skip to content

Instantly share code, notes, and snippets.

@wushbin
Created February 16, 2020 02:02
Show Gist options
  • Save wushbin/00c96298a0dd9c3b6c5ab59ac5e99f7a to your computer and use it in GitHub Desktop.
Save wushbin/00c96298a0dd9c3b6c5ab59ac5e99f7a to your computer and use it in GitHub Desktop.
class Solution {
public int findMinDifference(List<String> timePoints) {
List<Integer> times = new ArrayList<>();
for (String tp : timePoints) {
times.add(readValue(tp));
}
Collections.sort(times);
int min = Integer.MAX_VALUE;
int len = times.size();
for (int i = 1; i < len; i++) {
min = Math.min(min, times.get(i) - times.get(i - 1));
}
min = Math.min(min, 24 * 60 + times.get(0) - times.get(len - 1));
return min;
}
private int readValue(String tp) {
int hr = 10 * (tp.charAt(0) - '0') + (tp.charAt(1) - '0');
int mint = 10 * (tp.charAt(3) - '0') + (tp.charAt(4) - '0');
return hr * 60 + mint;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment