Java treeSet O(N * lgN)


  • 0
    C
        public int findMinDifference(List<String> timePoints) {
            TreeSet<Integer> result = new TreeSet<>();
            for (String each : timePoints) {
                String[] time = each.split(":");
                int currentTime = Integer.valueOf(time[0]) * 60 + Integer.valueOf(time[1]);
                if (!result.add(currentTime)) {
                    return 0;
                }
            }
            Integer previous = null;
            int diff = Integer.MAX_VALUE;
            for (Integer current : result) {
                if (null != previous) {
                    diff = Math.min(diff, current - previous);
                }
                previous = current;
            }
            diff = Math.min(diff, result.first() + 24 * 60 - result.last());
            return diff;
        }
    }

Log in to reply
 

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