LeetCode#539-最小时间差
import java.util.Arrays; import java.util.List; public class p539 { public static int findMinDifference(List<String> timePoints) { int min=24*60; int nums[]=new int[timePoints.size()]; for(int i=0;i<timePoints.size();i++){ String s= timePoints.get(i); String arr[]=s.split("\\:"); nums[i]=Integer.parseInt(arr[0])*60+Integer.parseInt(arr[1]); } Arrays.sort(nums); for(int i=0;i<nums.length-1;i++){ int num=nums[i+1]-nums[i]; min=Math.min(min,num); } int num=24*60-nums[nums.length-1]+nums[0]; min=Math.min(min,num); return min; } public static void main(String[] args) { } }
运行结果: