标签:pac har http over override tco com task nbsp
Fancy
https://leetcode.com/problems/task-scheduler/discuss/104496/concise-Java-Solution-O(N)-time-O(26)-space
1 class Solution { 2 public int leastInterval(char[] tasks, int n) { 3 if(n == 0) return tasks.length; 4 if(tasks.length == 0) return 0; 5 int[][] record = new int[26][2]; 6 for(int i = 0; i < tasks.length; i++){ 7 record[tasks[i] - ‘A‘][0]++; 8 } 9 Arrays.sort(record, new Comparator<int[]>(){ 10 @Override 11 public int compare(int[] a, int[] b){ 12 return b[0] - a[0]; 13 } 14 }); 15 int max = 1; 16 int i = 0; 17 while(record[i][0] == record[++i][0]) max++; 18 return Math.max(tasks.length, (record[0][0]-1) * (n+1) + max); 19 20 } 21 }
标签:pac har http over override tco com task nbsp
原文地址:https://www.cnblogs.com/goPanama/p/9821586.html