Java array sort simple solution


  • 0
    K
    class Solution {
        public int findMinDifference(List<String> timePoints) {
            int len = timePoints.size();
            int[] num = new int[len];
            for(int i=0;i<len;i++){
                String[] s = timePoints.get(i).split(":");
                int h = Integer.parseInt(s[0]), m = Integer.parseInt(s[1]);
                num[i]=h*60+m;
            }
            
            Arrays.sort(num);
            int min = Integer.MAX_VALUE;
            for(int i=0;i<len-1;i++){
                min=Math.min(min,num[i+1]-num[i]);
            }
            int val= 24*60-num[len-1]+num[0];
            return min<val? min:val;
        }
    }
    

Log in to reply
 

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