GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaInterview/java/src/LeetCode/TaskScheduler_621.java at master · damaohongtu/JavaInterview

Expand file tree

/

TaskScheduler_621.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
40 lines (37 loc) · 1.11 KB
/

TaskScheduler_621.java

Copy path

File metadata and controls

40 lines (37 loc) · 1.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package LeetCode;
import java.util.*;
/**
* @Classname TaskScheduler_621
* @Description 同一种任务之间必须间隔n秒,求出最少需要的时间,中间间隔不够的使用哑间隔进行填充!
* @Date 19-5-14 下午9:15
* @Created by mao<[email protected]>
*/
public class TaskScheduler_621 {
public int leastInterval(char[] tasks, int n) {
Map<Character,Integer> count=new HashMap<>();
for(int i=0;i<tasks.length;i++){
if(count.containsKey(tasks[i])){
int value=count.get(tasks[i])+1;
count.put(tasks[i],value);
}else{
count.put(tasks[i],1);
}
}
int len=count.size();
ArrayList<Integer> result=new ArrayList<>();
for(Character key:count.keySet()){
result.add(count.get(key));
}
Collections.sort(result);
int a=1;
int b=result.get(len-1);
for(int j=len-2;j>=0;j--){
if(result.get(j)==b){
a++;
}else {
break;
}
}
return a*b+(n-b+1)*(a-1);
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.