publicclassSolution{ publicintfindMinDifference(List<String> timePoints){ List<Point> list = new ArrayList<>(); for (String s : timePoints) { list.add(new Point(s)); } list.sort(Point::compareTo); Point p0 = list.get(0); list.add(new Point(p0.hour + 24, p0.minute)); int result = Integer.MAX_VALUE; int half = 12 * 60; Point pre = list.get(0); for (int i = 1; i < list.size(); i++) { Point p = list.get(i); int diff = p.getMinute() - pre.getMinute(); result = Math.min(result, diff > half ? 2 * half - diff : diff); pre = p; } return result; }
privatestaticclassPointimplementsComparable<Point> { int hour; int minute;