Two lines by Java 8


  • 0
    X
    public int findMinDifference(List<String> timePoints) {
        final int[] a = timePoints.stream().map(s -> s.split(":")) //
                .mapToInt(s -> Integer.parseInt(s[0]) * 60 + Integer.parseInt(s[1])).sorted().toArray();
    
        return IntStream.range(1, a.length).reduce(a[0] + 1440 - a[a.length - 1], (r, i) -> Math.min(r, a[i] - a[i - 1]));
    }
    

Log in to reply
 

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