-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ621.java
More file actions
29 lines (29 loc) · 732 Bytes
/
Q621.java
File metadata and controls
29 lines (29 loc) · 732 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
/*
* @Author: Shawn Yang
* @Date: 2019-09-19 07:43:27
* @Last Modified by: Shawn Yang
* @Last Modified time: 2019-09-19 07:43:40
*/
public class Solution {
public int leastInterval(char[] tasks, int n) {
int[] map = new int[26];
for (char c: tasks)
map[c - 'A']++;
Arrays.sort(map);
int time = 0;
while (map[25] > 0) {
map[25] -= 1;
time += 1;
int i = 1;
while(i <= n && map[25] > 0) {
if(i <= 25 && map[25 - i] > 0) {
map[25 - i] -= 1;
}
time += 1;
i += 1;
}
Arrays.sort(map);
}
return time;
}
}