# Java 10 liner solution. Simplest so far

• ``````public class Solution {
public int findMinDifference(List<String> timePoints) {
int mm = Integer.MAX_VALUE;
List<Integer> time = new ArrayList<>();

for(int i = 0; i < timePoints.size(); i++){
Integer h = Integer.valueOf(timePoints.get(i).substring(0, 2));
time.add(60 * h + Integer.valueOf(timePoints.get(i).substring(3, 5)));
}

Collections.sort(time, (Integer a, Integer b) -> a - b);

for(int i = 1; i < time.size(); i++){
System.out.println(time.get(i));
mm = Math.min(mm, time.get(i) - time.get(i-1));
}

int corner = time.get(0) + (1440 - time.get(time.size()-1));
return Math.min(mm, corner);
}
}``````

• ``````public int findMinDifference(List<String> timePoints) {
int mm = Integer.MAX_VALUE;
List<Integer> time = new ArrayList<>();

for(int i = 0; i < timePoints.size(); i++){
Integer h = Integer.valueOf(timePoints.get(i).substring(0, 2));
time.add(60 * h + Integer.valueOf(timePoints.get(i).substring(3, 5)));
}

Collections.sort(time, (Integer a, Integer b) -> a - b);
for(int i = 1; i < time.size(); i++) mm = Math.min(mm, time.get(i) - time.get(i-1));
int corner = time.get(0) + (1440 - time.get(time.size()-1)); //1440 = 24*60

return Math.min(mm, corner);
}``````

• A similar solution with a little bit more Java 8.

``````public class Solution {
public int findMinDifference(List<String> timePoints) {
int[] minutes = timePoints.stream().mapToInt((s) -> {
String[] value = s.split(":");
return 60 * Integer.parseInt(value[0]) + Integer.parseInt(value[1]);
}).sorted().toArray();

int min = IntStream.range(0, minutes.length - 1)
.map(i -> minutes[i + 1] - minutes[i])
.min()
.getAsInt();

int corner = minutes[0] + (1440 - minutes[minutes.length - 1]);
return Math.min(min, corner);
}
}
``````

• ``````public int findMinDifference(List<String> list) {
if(list == null || list.size() == 0) return 0;
int[] min = new int[] {Integer.MAX_VALUE};
Collections.sort(list, (a, b) -> {min[0] = Math.min(diff(a, b, 0), min[0]); return a.compareTo(b);});
return Math.min(min[0], diff(list.get(0), list.get(list.size() - 1), 24 * 60));
}
private int diff(String a, String b, int extraMins) {
String[] aa = a.split(":"), bb = b.split(":");
int minA = Integer.parseInt(aa[0]) * 60 + Integer.parseInt(aa[1]) + extraMins;
int minB = Integer.parseInt(bb[0]) * 60 + Integer.parseInt(bb[1]);
return Math.abs(minA - minB);
}``````

• @bin01 Lovely solution

• ‘’‘

``````public int findMinDifference(List<String> timePoints) {
Collections.sort(timePoints);
int min = 1440;
for(int i=1;i<timePoints.size();i++){
min = Math.min(min, diff(timePoints.get(i-1), timePoints.get(i)));
}
min = Math.min(min, 1440-diff(timePoints.get(0), timePoints.get(timePoints.size()-1)));
return min;
}
``````

‘’‘

``````private int diff(String t1, String t2){
int h1 = Integer.parseInt(t1.split(":")[0]);
int m1 = Integer.parseInt(t1.split(":")[1]);

int h2 = Integer.parseInt(t2.split(":")[0]);
int m2 = Integer.parseInt(t2.split(":")[1]);

int difH = h2-h1;
int difM = m2-m1;

return difH * 60 + difM;
}
``````

‘’‘

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.