Clear short Java Solution time: O(n) space: O(n)


  • 0
    F
    public int findMinDifference(List<String> timePoints) {
    	List<Integer> times = new ArrayList<>();
    	for (String time : timePoints) {
    		int h = Integer.valueOf(time.substring(0, 2));
    		int m = Integer.valueOf(time.substring(3));
    		times.add(h * 60 + m);
    	}
    	Collections.sort(times);
    	int min = Integer.MAX_VALUE;
    	for(int i=1;i<times.size();i++){
    		int diff = times.get(i)-times.get(i-1);
    		min = Math.min(min, diff);			
    	
    	}
    	int diff = times.get(times.size()-1)-times.get(0);
    	return Math.min(min, 1440-diff);        
    }

Log in to reply
 

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