-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path621.task-scheduler.java
More file actions
32 lines (27 loc) · 862 Bytes
/
Copy path621.task-scheduler.java
File metadata and controls
32 lines (27 loc) · 862 Bytes
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
class Solution {
public int leastInterval(char[] tasks, int n) {
if(n==0)
return tasks.length;
int[] mpr = new int[26];
int max_c = 0;
int no_max_c = 0;
int min_c = Integer.MAX_VALUE;
int no_min_c = 0;
for(char task: tasks){
mpr[task-'A']++;
if(max_c < mpr[task-'A']){
max_c = mpr[task-'A'];
no_max_c = 1;
}
else if(max_c == mpr[task-'A'])
no_max_c++;
if(min_c > mpr[task-'A']){
min_c = mpr[task-'A'];
no_min_c = 1;
}
else if(min_c == mpr[task-'A'])
no_min_c++;
}
return Math.max(tasks.length, (max_c-1)*(n+1) + no_max_c);
}
}