public int[] solution(int[] bedTime, int[][] naozhong){ Arrays.sort(naozhong, new Comparator<int[]>() { public int compare(int[] o1, int[] o2){ if(o1[0] == o2[0]){ return o1[1] - o2[1]; } return o1[0] - o2[0]; } }); int bed = arrToTime(bedTime); if(bed < arrToTime(naozhong[0])){ return timeToArr(arrToTime(naozhong[0]) - bed); } if(bed > arrToTime(naozhong[naozhong.length - 1])){ return timeToArr(bed - arrToTime(naozhong[naozhong.length - 1])) } for(int i = 0;i < naozhong.length;++i){ int t = arrToTime(naozhong[i]); if(t >= bed){ return timeToArr(t - bed); } } } private static int arrToTime(int[] nums) { return nums[0] * 60 + nums[1]; } private static int[] timeToArr(int time) { return new int[] { time / 60, time % 60 }; }
点赞 1
牛客网
牛客企业服务