621. Task Scheduler

Posted gopanama

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了621. Task Scheduler相关的知识,希望对你有一定的参考价值。

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 }

 


以上是关于621. Task Scheduler的主要内容,如果未能解决你的问题,请参考以下文章

[LeetCode 621] Task Scheduler

[LeetCode 621] Task Scheduler

621. Task Scheduler

621. Task Scheduler

621. Task Scheduler

621. Task Scheduler