码迷,mamicode.com
首页 > 其他好文 > 详细

621. Task Scheduler

时间:2018-10-20 16:17:43      阅读:154      评论:0      收藏:0      [点我收藏+]

标签: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 }

 

621. Task Scheduler

标签:pac   har   http   over   override   tco   com   task   nbsp   

原文地址:https://www.cnblogs.com/goPanama/p/9821586.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!